Ideas for Python 3

Michael Walter cm at leetspeak.org
Tue Apr 27 20:22:55 EDT 2004


David MacQuigg wrote:
 > [...]
> It took me a long time to realize that lamdas have only one advantage
> over named functions - they can be crammed into a tight space.  Here
> is an example:
> 
> L = [(lambda x: x**2), (lambda x:x**3), (lambda x:x**4), (lambda
> x:x**5)]
> 
> If the purpose is to save space, wouldn't this be better as:
> 
> L = [:x:x**2, :x:x**3, :x:x**4 :x:x**5]
   L = map(lambda x: lambda y: x**y,range(2,6))

Almost. Or write mapc ("map currying") and have:

   L = mapc(pow,range(2,6))

Shorter than your example, less mistake-prone, no obvious lambda at all ;)

Cheers,
Michael



More information about the Python-list mailing list