else in list comp

Cliff Wells clifford.wells at attbi.com
Thu Jan 30 00:56:47 EST 2003


On Wed, 2003-01-29 at 18:01, Greg Ewing (using news.cis.dfn.de) wrote:
> Cliff Wells wrote:
> 
> > What I thought of first:
> > 
> > ['' for i in l if i is None else i]
> > 
> > Any thoughts on something like this?
> 
> 
> I don't think you've thought this through properly. Consider
> that a list comp can have multiple if and/or for clauses
> interspersed. How would your proposed feature work in the
> general case?

In a very unreadable fashion?

> Also, you need to understand that an if clause in a list
> comp decides *whether* to include an item in the list;
> it doesn't decide *what* to include in the list. Given
> that, I can't see that attaching an else clause to it
> makes any sense.

Okay.

-- 
Cliff Wells <clifford.wells at attbi.com>






More information about the Python-list mailing list