Path: csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!news.alt.net!news.astraweb.com!border6.newsrouter.astraweb.com!not-for-mail From: Ben Finney Newsgroups: comp.lang.python Subject: Re: Converting a set into list References: X-Public-Key-ID: 0xAC128405 X-Public-Key-Fingerprint: 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405 X-Public-Key-URL: http://www.benfinney.id.au/contact/bfinney-pubkey.asc X-Post-From: Ben Finney Date: Sun, 15 May 2011 00:12:31 +1000 Message-ID: <87iptdid68.fsf@benfinney.id.au> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) Cancel-Lock: sha1:cQFw7FoefbbVzu57iBlmOBZOOlA= MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Lines: 47 Organization: Unlimited download news at news.astraweb.com NNTP-Posting-Host: 209f2469.news.astraweb.com X-Trace: DXC=PlE:VjSGg>cN4DY]]om;IiL?0kYOcDh@jSBc;\8ijUdkZ_f^EkEQhFgUGD@iN[Hd?oH5YjW4;ChE` Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5365 TheSaint writes: > Hello > > I've stumble to find a solution to get a list from a set > > > > >>> aa= ['a','b','c','f'] Creates a new list object. Binds the name ‘aa’ to that object. > >>> aa > ['a', 'b', 'c', 'f'] Evaluates the object referenced by the name ‘aa’. > >>> set(aa) > {'a', 'c', 'b', 'f'} Creates a new set object, populating it with the contents from the list object referenced by ‘aa’. Doesn't do anything with the new set object, which will soon be garbage-collected. > >>> [k for k in aa] > ['a', 'b', 'c', 'f'] Creates a new list object by iterating each of the items from the list referenced by ‘aa’. Does nothing with the new list object, which will soon be garbage-collected. > > I repute the comprehension list too expensive, is there another method? Another method to do what? If you want to bind ‘aa’ to a new object, do so with an assignment statement. (Your example has exactly one assignment statement; all the other statements create objects which are never bound to anything.) But what is it you actually want to do? -- \ “The fact that I have no remedy for all the sorrows of the | `\ world is no reason for my accepting yours. It simply supports | _o__) the strong probability that yours is a fake.” —Henry L. Mencken | Ben Finney