list of lambda

Leif K-Brooks eurleif at ecritters.biz
Fri Nov 11 21:18:11 EST 2005


jena wrote:
> hello,
> when i create list of lambdas:
> l=[lambda:x.upper() for x in ['a','b','c']]
> then l[0]() returns 'C', i think, it should be 'A'

Fredrik Lundh provided the general solution, but in this specific case,
the simplest solution is:

l = [x.upper for x in ['a', 'b', 'c']]



More information about the Python-list mailing list