Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5355 > unrolled thread

Converting a set into list

Started byTheSaint <nobody@nowhere.net.no>
First post2011-05-14 17:02 +0800
Last post2011-05-17 01:07 +0000
Articles 2 on this page of 22 — 11 participants

Back to article view | Back to comp.lang.python


Contents

  Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-14 17:02 +0800
    Re: Converting a set into list Peter Otten <__peter__@web.de> - 2011-05-14 11:33 +0200
      Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-14 22:14 +0800
        Re: Converting a set into list Chris Angelico <rosuav@gmail.com> - 2011-05-15 04:22 +1000
    Re: Converting a set into list Ben Finney <ben+python@benfinney.id.au> - 2011-05-15 00:12 +1000
      Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-14 22:51 +0800
        Re: Converting a set into list Ben Finney <ben+python@benfinney.id.au> - 2011-05-15 09:21 +1000
          Re: Converting a set into list Chris Torek <nospam@torek.net> - 2011-05-15 02:11 +0000
            Re: Converting a set into list SigmundV <sigmundv@gmail.com> - 2011-05-15 04:18 -0700
              Re: Converting a set into list SigmundV <sigmundv@gmail.com> - 2011-05-15 04:23 -0700
              Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-15 23:56 +0800
                Re: Converting a set into list Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2011-05-15 22:27 +0200
                  Re: Converting a set into list Daniel Kluev <dan.kluev@gmail.com> - 2011-05-16 13:37 +1100
                  Re: Converting a set into list Peter Otten <__peter__@web.de> - 2011-05-16 08:34 +0200
                  Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-16 22:23 +0800
                    Re: Converting a set into list Ben Finney <ben+python@benfinney.id.au> - 2011-05-17 10:33 +1000
              Re: Converting a set into list Roy Smith <roy@panix.com> - 2011-05-15 13:07 -0400
            Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-16 00:05 +0800
              Re: Converting a set into list Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-15 16:28 +0000
                Re: Converting a set into list TheSaint <nobody@nowhere.net.no> - 2011-05-16 00:35 +0800
            Re: Converting a set into list Duncan Booth <duncan.booth@invalid.invalid> - 2011-05-16 10:24 +0000
              Re: Converting a set into list Chris Torek <nospam@torek.net> - 2011-05-17 01:07 +0000

Page 2 of 2 — ← Prev page 1 [2]


#5508

FromDuncan Booth <duncan.booth@invalid.invalid>
Date2011-05-16 10:24 +0000
Message-ID<Xns9EE772D313153duncanbooth@127.0.0.1>
In reply to#5403
Chris Torek <nospam@torek.net> wrote:

>     >>> x = [3, 1, 4, 1, 5, 9, 2, 6]
>     >>> x
>     [3, 1, 4, 1, 5, 9, 2, 6]
>     >>> list(set(x))
>     [1, 2, 3, 4, 5, 6, 9]
>     >>>
> 
> Of course, this trick only works if all the list elements are
> hashable.
> 
> This might not be the best example since the result is sorted
> "by accident", while other list(set(...)) results are not. 

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]


-- 
Duncan Booth http://kupuguy.blogspot.com

[toc] | [prev] | [next] | [standalone]


#5544

FromChris Torek <nospam@torek.net>
Date2011-05-17 01:07 +0000
Message-ID<iqshot03q0@news4.newsguy.com>
In reply to#5508
>Chris Torek <nospam@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@127.0.0.1>,
Duncan Booth  <duncan.booth@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

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web