Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.038 X-Spam-Evidence: '*H*': 0.92; '*S*': 0.00; 'subject:two': 0.07; 'tuple': 0.09; 'elements,': 0.16; 'l1,': 0.16; 'subject:list': 0.18; '>>>': 0.18; 'this?': 0.21; 'header:In-Reply-To:1': 0.22; 'separate': 0.28; 'lists': 0.28; 'message-id:@mail.gmail.com': 0.29; 'url:library': 0.31; 'subject:?': 0.31; 'list': 0.32; 'there': 0.33; 'to:addr:python-list': 0.33; '...': 0.34; 'url:python': 0.36; 'subject:lists': 0.36; 'two': 0.37; 'received:google.com': 0.38; 'url:org': 0.38; 'received:209.85': 0.38; 'subject:: ': 0.39; 'url:docs': 0.39; 'to:addr:python.org': 0.39; 'url:functions': 0.84 MIME-Version: 1.0 Sender: z@etiol.net X-Originating-IP: [190.52.51.219] In-Reply-To: References: Date: Sat, 6 Aug 2011 13:30:49 -0400 X-Google-Sender-Auth: L7Y6EEm1BBpRtG7if6nQCSGoWRI Subject: Fwd: how to separate a list into two lists? From: Zero Piraeus To: python-list@python.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312651853 news.xs4all.nl 23956 [2001:888:2000:d::a6]:53085 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10979 : > if a list L is composed with tuple consists of two elements, that is > L =3D [(a1, b1), (a2, b2) ... (an, bn)] > > is there any simple way to divide this list into two separate lists , suc= h that > L1 =3D [a1, a2... an] > L2=3D[b1,b2 ... bn] How about this? >>> L =3D [("a1", "b1"), ("a2", "b2"), ("an", "bn")] >>> L1, L2 =3D zip(*L) >>> L1 ('a1', 'a2', 'an') >>> L2 ('b1', 'b2', 'bn') http://docs.python.org/library/functions.html#zip =C2=A0-[]z.