Ordering python sets

Peter Otten __peter__ at web.de
Wed Oct 22 13:23:39 EDT 2008


Peter Pearson wrote:

> On Wed, 22 Oct 2008 15:37:03 +0200, Peter Otten <__peter__ at web.de> wrote:
>> Tim Chase wrote:
>>
>>> Though for each test, in 2.3, 2.4, and 2.5 that I've got
>>> installed on my local machine, they each printed "s" in-order,
>>> and the iteration occurred in-order as well, even without the
>>> added "sorted(list(s))" code.
>>
>> You need more tests then ;)
>>
>>>>> list(set([1,1000]))
>> [1000, 1]
> 
> So one wonders, of course, why Mr. Otten chose 1000; and one explores:
> 
> $ python
> Python 2.4.3 (#2, Jul 31 2008, 21:56:52)
> [snip]
>>>> for x in 2, 100, 199, 200, 300, 400, 500, 600:
> ...   list( set( [ 1, x ] ) )
> ...
> [1, 2]
> [1, 100]
> [1, 199]
> [200, 1]
> [1, 300]
> [400, 1]
> [1, 500]
> [600, 1]
>>>>

Here's another one:

>>> set([1,9])
set([1, 9])
>>> set([9,1])
set([9, 1])

This time I did indeed search systematically...

Peter




More information about the Python-list mailing list