list of lambda

bonono at gmail.com bonono at gmail.com
Sat Nov 12 04:11:19 CET 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