[Python-ideas] Add orderedset as set(iterable, *, ordered=False) and similarly for frozenset.
Ed Kellett
edk141 at gmail.com
Sun Feb 8 00:02:05 CET 2015
On Sat Feb 07 2015 at 10:37:39 PM Chris Angelico <rosuav at gmail.com> wrote:
> Set union is, but sets lack order. Once you add order to a set, it
> becomes more like a list
Then wouldn't adding .extend() and + make more sense anyway? List-like
operations should look like the list-like operations we already have.
> so the union of x and y might not be identical to the union of y and x
Well, not if you define union to be non-commutative, no—but that's what
we're discussing.
> They'd be the same modulo order, so it's not breaking the concept of set
> union.
Sure it is: operations are supposed to yield things that make sense. Set
union yields the set of elements contained in any of its operands; even if
its operands have orderings that make sense, the ordering between sets
might be partial or inconsistent, so the result cannot. So the existing
definition of set union can never produce a correct ordering.
I can't see why it would be preferable to redefine union as concatenation
rather than just supporting explicit concatenation. Apart from feeling more
mathematically sound to me, it's better at documenting intention: which
method (or operator) you choose reflects whether you're interested in the
order of the result or just its contents.
Ed Kellett
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150207/af3e43d5/attachment.html>
More information about the Python-ideas
mailing list