Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #10979 > unrolled thread

Fwd: how to separate a list into two lists?

Started byZero Piraeus <schesis@gmail.com>
First post2011-08-06 13:30 -0400
Last post2011-08-06 13:30 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Fwd: how to separate a list into two lists? Zero Piraeus <schesis@gmail.com> - 2011-08-06 13:30 -0400

#10979 — Fwd: how to separate a list into two lists?

FromZero Piraeus <schesis@gmail.com>
Date2011-08-06 13:30 -0400
SubjectFwd: how to separate a list into two lists?
Message-ID<mailman.1988.1312651853.1164.python-list@python.org>
:

> 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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web