using lambda to print everything in a list

Christian Tanzer tanzer at swing.co.at
Sun Apr 29 07:13:51 EDT 2001


scarblac at pino.selwerd.nl wrote:

> Christian Tanzer <tanzer at swing.co.at> wrote in comp.lang.python:
> > 
> > "Alex Martelli" <aleaxit at yahoo.com> wrote:
> > 
> > > My personal impression is that lambda is a (minor)
> > > nuisance.  Naming the code fragment that you want
> > > to pass to some other function, by making it a
> > > nested function, seems clearer & handier to me.
> > 
> > What about using `map' to apply a method to each element in a list?
> > 
> > Like in: 
> > 
> >     map (lambda s : s.capitalize (), l)
> > 
> > I wouldn't call a loop clearer in this case, despite the lambda.
> 
> That is debatable, but the list comprehension is fine:
> 
>       [ s.capitalize() for s in l ]

Yes, that is the best alternative. Hope I get rid of 1.5.2 soon.

> > For strings, one could of course pass `string.capitalize' to `map'.
> > Unfortunately, this loop hole exists only for strings, and the powers
> > that be plan on making the string module obsolete, anyway.
> 
> I really don't think they plan on that.

IIRC a while ago there was quite some discussion on deprecating the
string module with the BDFL clearly in favor of doing so.

-- 
Christian Tanzer                                         tanzer at swing.co.at
Glasauergasse 32                                       Tel: +43 1 876 62 36
A-1130 Vienna, Austria                                 Fax: +43 1 877 66 92





More information about the Python-list mailing list