Converting a set into list

Ben Finney ben+python at benfinney.id.au
Mon May 16 20:33:16 EDT 2011


TheSaint <nobody at nowhere.net.no> writes:

> Thomas Rachel wrote:
>
> > Which loops do you mean here?
>
> list(set) has been proved to largely win against
> list = []
> for item in set:
>     list.append(item)
> or [list.append(item) for item in set]

Remember that the criterion of speed is a matter of the implementation,
and what's fast on one won't necessarily be fast on others. Which
implementations did you try?

Where I do agree is that ‘list(foo)’ wins over the other examples you
show on the important criteria of concision and readability.

-- 
 \          “A thing moderately good is not so good as it ought to be. |
  `\        Moderation in temper is always a virtue; but moderation in |
_o__)                       principle is always a vice.” —Thomas Paine |
Ben Finney



More information about the Python-list mailing list