Ordering python sets

Peter Otten __peter__ at web.de
Wed Oct 22 09:37:03 EDT 2008


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]

By the way, sorted(s) is sufficient; sorted() accepts arbitrary iterables.

Peter



More information about the Python-list mailing list