lambda expression

Janos Blazi jblazi at vipsurf.de
Tue Aug 8 16:25:47 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.

Thx. I am sure I should have never found out how to do it! Well, it works.
J.B.




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list