how to separate a list into two lists?

Chris Angelico rosuav at gmail.com
Sat Aug 6 21:05:14 EDT 2011


On Sun, Aug 7, 2011 at 1:58 AM, Tim Roberts <timr at probo.com> wrote:
> I did momentarily consider the following slimy solution:
>  L1 = dict(L).keys()
>  L2 = dict(L).values()
> but that reorders the tuples.  They still correspond, but in a different
> order.
>

Which can be overcome with collections.OrderedDict. But what's dict(L)
going to do? It's going to loop over L, more than once in fact.

I guess the real question is: Why do you wish to avoid a loop?

ChrisA



More information about the Python-list mailing list