RELEASED Python 2.4, alpha 1

Christopher T King squirrel at WPI.EDU
Fri Jul 9 14:52:32 EDT 2004


On 9 Jul 2004, Michele Simionato wrote:

> Uhm ... I see generator expressions have late bindings, just as list
> comprehensions:
>
> >>> f1,f2,f3=tuple(lambda : i for i in [1,2,3])
> >>> f1()
> 3
> >>> f2()
> 3
> >>> f3()
> 3

I think this is a property of lambdas (or functions in general), rather 
than comprehensions:

>>> i=1
>>> f1=lambda: i
>>> i=2
>>> f2=lambda: i
>>> i=3
>>> f3=lambda: i
>>> f1()
3
>>> f2()
3
>>> f3()
3




More information about the Python-list mailing list