Fwd: how to separate a list into two lists?
Zero Piraeus
schesis at gmail.com
Sat Aug 6 13:30:49 EDT 2011
:
> if a list L is composed with tuple consists of two elements, that is
> L = [(a1, b1), (a2, b2) ... (an, bn)]
>
> is there any simple way to divide this list into two separate lists , such that
> L1 = [a1, a2... an]
> L2=[b1,b2 ... bn]
How about this?
>>> L = [("a1", "b1"), ("a2", "b2"), ("an", "bn")]
>>> L1, L2 = zip(*L)
>>> L1
('a1', 'a2', 'an')
>>> L2
('b1', 'b2', 'bn')
http://docs.python.org/library/functions.html#zip
-[]z.
More information about the Python-list
mailing list