2D List comprehension & replace

Greg Ewing (using news.cis.dfn.de) wmwd2zz02 at sneakemail.com
Thu Mar 11 22:34:51 EST 2004


Paul McGuire wrote:
> "Larry Bates" <lbates at swamisoft.com> wrote in message
> news:ZOednXPakP64mczdRVn-jA at comcast.com...
> 
>>[[y or None for y in x] for x in l]
> 
> Well if that works, then this must too:
> 
>      [y or None for x in l for y in x]

No, that will give you a single-level list,
not a list of lists.

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list