Not understanding lamdas and scoping
George Sakkis
george.sakkis at gmail.com
Wed Mar 26 21:02:35 EDT 2008
On Mar 26, 6:03 pm, Joshua Kugler <jkug... at bigfoot.com> wrote:
> George Sakkis wrote:
> > On Mar 26, 5:02 pm, Joshua Kugler <jkug... at bigfoot.com> wrote:
>
> >> I am trying to use lamdba to generate some functions, and it is not
> >> working
> >> the way I'd expect. The code is below, followed by the results I'm
> >> getting. More comments below that.
>
> >> (...)
>
> >> So, is there some scoping issue with lambda
> >> that I'm not seeing?
>
> > Yes; it's not related to lambda though but to closures (whether
> > defined as lambdas or regular functions). See for example
>
> http://groups.google.com/group/comp.lang.python/browse_frm/thread/94d...
>
>
>
> > There should be an entry for this at
> >http://www.python.org/doc/faq/programming/, that's really an FAQ.
>
> George -
>
> Thanks for the quick and clear answer...that makes perfect sense. To
> bad...I'd like to just use a list comprehension. :)
Did you actually read the replies on that thread ? You _can_ use a
list comprehension or a loop, all you have to do is bind the passed
values as default parameters:
rules = [make_pattern(pattern=p, search=s, replace=r)
for (p,s,r) in patterns]
George
More information about the Python-list
mailing list