Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Duncan Booth Newsgroups: comp.lang.python Subject: Re: Converting a set into list Date: 16 May 2011 10:24:28 GMT Lines: 29 Message-ID: References: <87iptdid68.fsf@benfinney.id.au> <871v00j2bh.fsf@benfinney.id.au> Reply-To: duncan.booth@suttoncourtenay.org.uk Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: individual.net nUOPTEHgGa4V/UwgB4rriAIlpQszPthDFasYML+lBzW/v6010G Cancel-Lock: sha1:9X+qiZnU2RI21akogMoAVX01+rk= User-Agent: Xnews/2006.08.24 Hamster/2.1.0.11 X-Face: .C;/v3#w@2k.C(.1v-}d=`|7AQ-%,#A$0ZGtAkLPvuawAM>3#D,pXaAb31%(=Gn2ZZK/Z~fd0y4't5iKK~F":}F2*|\mQYX+BUr4ZM*|+`@o-TKzFGwsJnan{)*b~QJ-Fu^u'$$nYV Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5508 Chris Torek 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