lambda expression
Alex
cut_me_out at hotmail.com
Tue Aug 8 15:23:35 EDT 2000
> I'd like to write something like
>
> u=filter(lambda x: k in d[x],u),
>
> where d is a dictionary, u is (of course) a list and k a variable declared
> in the function where the lines is in. But i does not work, it seems, k ist
> not known inside of the lambda expression.
> Any suggestions? Any help?
The usual trick is to use default arguments. E.g.
u=filter(lambda x, k=k: k in d[x],u)
Alex.
More information about the Python-list
mailing list