2D List comprehension & replace

Paul McGuire bogus at bogus.net
Thu Mar 11 23:30:59 EST 2004


"Greg Ewing (using news.cis.dfn.de)" <wmwd2zz02 at sneakemail.com> wrote in
message news:c2rb4r$21ftn5$2 at ID-169208.news.uni-berlin.de...
> 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
>
Shoot!  Well, thanks for straightening me out!  I'll fix this in my Matlab
wrapper class, too.

-- Paul





More information about the Python-list mailing list