Concatenating a list of lists

Erik Max Francis max at alcyone.com
Sat Aug 17 16:22:35 EDT 2002


Neophytos Michael wrote:

> 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:
> 
> def red_aux(l1, l2):
>     l1.extend(l2);
>     return l1;
> 
> dest_list = reduce(red_aux, src_list, []);

Why not just

	reduce(operator.add, srcList, [])

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ There is nothing so subject to the inconstancy of fortune as war.
\__/ Miguel de Cervantes
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.



More information about the Python-list mailing list