Concatenating a list of lists
Stas Z.
stas at linux.isbeter.nl
Sun Aug 18 04:25:25 EDT 2002
On Sun, 18 Aug 2002 02:56:07 +0200, Wojtek Walczak wrote:
> 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]
For speed:
>>> map(b.extend,a)
IMHO, this is also more pythonisch. -)
--
We are Debian GNU/Linux...
...Resistance is measured in ohm's
More information about the Python-list
mailing list