Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5365
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Converting a set into list |
| References | <iqlgj4$iet$1@speranza.aioe.org> |
| Date | 2011-05-15 00:12 +1000 |
| Message-ID | <87iptdid68.fsf@benfinney.id.au> (permalink) |
| Organization | Unlimited download news at news.astraweb.com |
TheSaint <nobody@nowhere.net.no> writes:
> Hello
>
> I've stumble to find a solution to get a list from a set
>
> <code>
>
> >>> 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.
> </code>
> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
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
csiph-web