list of lambda

bonono at gmail.com bonono at gmail.com
Fri Nov 11 22:11:19 EST 2005


Leif K-Brooks wrote:
> 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']]

how about :

l = ['A','B','C']




More information about the Python-list mailing list