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

Tim Peters tim.one@comcast.net
Mon, 19 Aug 2002 17:48:15 -0400


[Guido]
> ...
> My current approach (now in CVS!) is to remove the sort_repr flag to
> the constructor, but to provide a method that can produce a sorted or
> an unsorted representation.

+1.  That's the best way to go.


> __repr__ will always return the items unsorted, which matches what repr
> (dict) does.  After all, I think it could be confusing to a user when
> 'print s' shows
>
>     Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>
> but
>
>     for i in s: print i,
>
> prints
>
>     9 8 7 6 5 4 3 2 1 0

>>> from sets import Set
>>> print Set(range(10))
Set([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>>

When I optimized a useless ~ out of the dict code for 2.2, it became much
more likely that the traversal order for an int-keyed dict would match
numeric order.  I have evidence that this has fooled newbies into believing
that dicts are ordered maps!  If it wouldn't cost an extra cycle, I'd be
tempted to slop the ~ back in again <0.9 wink>.