Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #10979
| References | <CAN1Fwxcdtt0u_TT=civMes1hA2qvfkH2YckES7B7qRE++DXzJQ@mail.gmail.com> <CANaSqUc9qsKmg4n11GLC6bWfiFXWL80uzmxECuk=ZgR1D77V1Q@mail.gmail.com> |
|---|---|
| Date | 2011-08-06 13:30 -0400 |
| Subject | Fwd: how to separate a list into two lists? |
| From | Zero Piraeus <schesis@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1988.1312651853.1164.python-list@python.org> (permalink) |
:
> 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.
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Fwd: how to separate a list into two lists? Zero Piraeus <schesis@gmail.com> - 2011-08-06 13:30 -0400
csiph-web