Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:two': 0.07; 'alias': 0.09; 'done?': 0.09; 'question:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'tuple': 0.09; 'elements,': 0.16; 'wrote:': 0.16; 'subject:list': 0.18; 'header:In-Reply-To:1': 0.22; 'loop,': 0.23; 'pm,': 0.24; 'aug': 0.24; 'separate': 0.28; 'lists': 0.28; 'asking': 0.29; 'sun,': 0.30; 'subject:?': 0.31; 'list': 0.32; 'there': 0.33; 'to:addr:python-list': 0.33; '...': 0.34; 'header:User-Agent:1': 0.34; 'header:X-Complaints-To:1': 0.35; 'subject:lists': 0.36; 'assuming': 0.37; 'thread': 0.37; 'two': 0.37; 'received:org': 0.38; 'subject:: ': 0.39; 'header :Mime-Version:1': 0.39; 'to:addr:python.org': 0.39 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Gelonida N Subject: Re: how to separate a list into two lists? Date: Sat, 06 Aug 2011 22:00:46 +0200 References: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: unicorn.dungeon.de User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.18) Gecko/20110617 Lightning/1.0b2 "" In-Reply-To: <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com> 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: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312661111 news.xs4all.nl 23967 [2001:888:2000:d::a6]:54853 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10987 On 08/06/2011 08:13 PM, bud wrote: > On Sun, 07 Aug 2011 01:07:00 +0800, smith jack wrote: > >> 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] >> >> i do not want to use loop, any methods to make this done? > > > (x,y) = [ [z[i] for z in L] for i in range(len(L[0]))] > > x > : ['a1', 'a2', 'an'] > > y > : ['b1', 'b2', 'bn'] > > Asuming you are not an alias of Jack Smith and assuming you did not see Jack's thread asking the same question: x,y = unzip(*L)