Py2.3: Feedback on Sets

Chris Reedy creedy at mitretek.org
Wed Aug 13 13:34:22 EDT 2003


Raymond -

    Well now that you ask ...

Raymond Hettinger wrote:
> I've gotten lots of feedback on the itertools module
> but have not heard a peep about the new sets module.
> 
> * Are you overjoyed/outraged by the choice of | and &
>    as set operators (instead of + and *)?

I think that choice appeals to me more than + and * (which are already
more overloaded than I would like). I haven't seen any suggestions that
I liked better.

> * Is the support for sets of sets necessary for your work
>    and, if so, then is the implementation sufficiently
>    powerful?

Yes I need it (desperately). Generally works as I need. However, see 
more comments below.

> * Is there a compelling need for additional set methods like
>    Set.powerset() and Set.isdisjoint(s) or are the current
>    offerings sufficient?

I haven't felt the need yet. So far I've been satisfied with:

      if x & y:

as opposed to

      if x.isdisjoint(y)

> * Does the performance meet your expectations?

So far. However, so far, I haven't been trying meet any demanding
performance requirements.

> * Do you care that sets can only contain hashable elements?

This is an interesting question. In particular, I have found myself on 
more than one occasion doing the following:

for x in interesting_objects:
     x.foo = Set()
while something_to_do:
     somex.foo |= something_I_just_computed
for x in interesting_objects:
     x.foo = ImmutableSet(x.foo)
build_some_more_sets(somex.foo)

I'm not sure whether I like having to go back and change all my sets to 
Immutable ones after I've finished the computation. (Or whether I just 
ought to make x.foo immutable all the time.) I did appreciate the 
ImmutableSet type, since it allows me to flag to myself that I don't 
expect a set to change further.

> * How about the design constraint that the argument to most
>    set methods must be another Set (as opposed to any iterable)?

In some cases I've run into that. Since I can create a set with any
iterable I've been able to do:

    set op Set(iterable)

I think I might be interested in using a general iterable if that would
get me some advantage (maybe significantly faster).

> * Are the docs clear?  Can you suggest improvements?

No problems here. However, my background is math, and I've never had
problems with documentation (I started my career learning IBM mainframe
assembly language programming from the reference manuals) so I don't
think I'm a good test case.

> * Are sets helpful in your daily work or does the need arise
>    only rarely?

I'm working on a project where they are critical. If it hadn't been
supplied I would have implemented one myself. I was using the backported
version of the set module with 2.2 before 2.3 came out.

> User feedback is essential to determining the future direction
> of sets (whether it will be implemented in C, change API,
> and/or be given supporting language syntax).
> 
> 
> Raymond Hettinger

    Chris



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----




More information about the Python-list mailing list