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


Groups > comp.lang.python > #10987

Re: how to separate a list into two lists?

From Gelonida N <gelonida@gmail.com>
Subject Re: how to separate a list into two lists?
Date 2011-08-06 22:00 +0200
References <mailman.1983.1312650424.1164.python-list@python.org> <4e3d8440$0$5872$c3e8da3$12bcf670@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.1994.1312661111.1164.python-list@python.org> (permalink)

Show all headers | View raw


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)


Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

how to separate a list into two lists? smith jack <thinke365@gmail.com> - 2011-08-07 01:07 +0800
  Re: how to separate a list into two lists? bud <only@fleshwound.org> - 2011-08-06 18:13 +0000
    Re: how to separate a list into two lists? Gelonida N <gelonida@gmail.com> - 2011-08-06 22:00 +0200
      Re: how to separate a list into two lists? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-07 10:07 +1000
        Re: how to separate a list into two lists? Gelonida N <gelonida@gmail.com> - 2011-08-07 19:11 +0200
  Re: how to separate a list into two lists? Tim Roberts <timr@probo.com> - 2011-08-06 17:58 -0700
    Re: how to separate a list into two lists? Chris Angelico <rosuav@gmail.com> - 2011-08-07 02:05 +0100
      Re: how to separate a list into two lists? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-08-07 11:35 +1000
  Re: how to separate a list into two lists? Paul Rubin <no.email@nospam.invalid> - 2011-08-06 22:29 -0700

csiph-web