Converting a set into list
Chris Torek
nospam at torek.net
Mon May 16 21:07:41 EDT 2011
>Chris Torek <nospam at torek.net> wrote:
>> >>> x = [3, 1, 4, 1, 5, 9, 2, 6]
>> >>> list(set(x))
>> This might not be the best example since the result is sorted
>> "by accident", while other list(set(...)) results are not.
In article <Xns9EE772D313153duncanbooth at 127.0.0.1>,
Duncan Booth <duncan.booth at suttoncourtenay.org.uk> wrote:
>A minor change to your example makes it out of order even for integers:
>
>>>> x = [7, 8, 9, 1, 4, 1]
>>>> list(set(x))
>[8, 9, 1, 4, 7]
>
>or for that mattter:
>
>>>> list(set([3, 32, 4, 32, 5, 9, 2, 6]))
>[32, 2, 3, 4, 5, 6, 9]
Yes, but then it is no longer "as easy as pi". :-)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: gmail (figure it out) http://web.torek.net/torek/index.html
More information about the Python-list
mailing list