[Python-Dev] Re: PEP 218 (sets); moving set.py to Lib

Guido van Rossum guido@python.org
Tue, 20 Aug 2002 20:37:49 -0400


> > I am still perplexed that I received *no* feedback on the sets
> > module
> 
> As I previously said, I feel comfortable with what I read and saw.
> I'd probably have to use sets for having more circumstantiated
> comments.

Fair enough.

> Unless you offer the source on c.l.py and ask for more users' opinions?

Last time I tried that it turned out a bad idea.  I prefer feedback
over a flame war.

> Maybe some people would have preferred to see more usual notation,
> like `+' for union and `*' for intersection, rather than `or' and
> `and'?  There are tiny pros and cons in each direction.  For one,
> I'll gladly use what is available, I'm not really going to crusade
> for either notation...

Um, the notation is '|' and '&', not 'or' and 'and', and those are
what I learned in school.  Seems pretty conventional to me (Greg
Wilson actually tried this out on unsuspecting newbies and found that
while '+' worked okay, '*' did not -- read the PEP).

But yes, this is decent feedback (with good enough arguments, Greg's
conclusion might even be overturned).

> Should there be special provisions for Sets to interoperate
> magically with lists or iterators?  Lists and iterators could be
> considered as ordered sets with duplicates allowed.  Even if it
> could be tinily useful, it is surely not difficult to explicitly
> "cast" lists and iterators using the `Set' constructor.  It is
> already easy to build an iterator or a list out of a set.

You can do an in-place union of a Set and a sequence or iterable with
set.update(seq).  If you want intersection or a difference, or your
set is immutable, you'd have to cast the sequence to a set.  What's
the use case?

Which brings me to another open issue.

set.update(seq) and set.add(element) have a provision to transform the
inserted element(s) to an ImmutableSet if needed.  Should the
constructor do the same?

> Criticism?  OK!  What about supporting infinite sets? :-) Anything else?
> Hmph!  The module doc-string has the word "actually" with three `l'! :-)

Not any more, thanks to Raymond Hettinger. :-)

--Guido van Rossum (home page: http://www.python.org/~guido/)