Concatenating a list of lists

Wojtek Walczak gminick at hacker.pl
Sun Aug 18 02:56:07 CEST 2002


Dnia 17 Aug 2002 13:17:19 -0700, Neophytos Michael napisał(a):
> A quick question for the python experts.  I have a list of lists (only
> one level) that I want to turn into a flat list.  What's the python
> way of achieving this?  I came up with:

>>> a = [ range(1,5), range(5,10) ]
>>> a
[[1, 2, 3, 4], [5, 6, 7, 8, 9]]
>>> b=[]
>>> [b.extend(i) for i in a]
[None, None]
>>> b
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>

-- 
[ Wojtek gminick Walczak ][ http://gminick.linuxsecurity.pl/ ]
[ gminick (at) hacker.pl ][ gminick (at) underground.org.pl/ ]



More information about the Python-list mailing list