[Python-ideas] Add orderedset as set(iterable, *, ordered=False) and similarly for frozenset.

Ed Kellett edk141 at gmail.com
Sun Feb 8 01:53:33 CET 2015


On Sun Feb 08 2015 at 12:34:48 AM Neil Girdhar <mistersheik at gmail.com>
wrote:

> If it were called UniqueList, I would agree with you.  Since it's called
> OrderedSet, I expect it to use the same operations as set.
>

I agree, and with that in mind, it seems wrong for it to redefine what
"union" means.


> Also, typically I implement something using set and then after the fact
> realize that I need ordering.  I then change the declaration to
> OrderedSet.  With your solution, I would have to also change | and |= to +
> and +=.  I feel that update should remain equivalent to |= rather than
> switching to +=,
>

That's a convenient case if you happened to |= other sets (which you also
had to change to OrderedSet) in in the correct order already, but if you
didn't or you wanted some particular interesting ordering or you were
getting your sets to add from somewhere that didn't deal in OrderedSets,
you'd have to change that part of your program to support ordering anyway.

On the other hand, if you were .update()ing directly from some other
ordered iterable, you wouldn't have to change anything. :)

Ed Kellett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150208/4cda0856/attachment-0001.html>


More information about the Python-ideas mailing list