RELEASED Python 2.4, alpha 1

Denis S. Otkidach ods at
Sat Jul 10 12:41:56 CEST 2004

On Sat, 9 Jul 2004, Michele Simionato wrote:

MS> The simplest workaround is Pythonic in the sense that it is
MS> explicit
MS> f1,f2,f3=tuple(lambda i=i: i for i in [1,2,3])
MS> as one explicitly rebinds "i" at each iteration but still I
MS> cannot
MS> find it other than hackish, since there is no point here in
MS> creating
MS> a function with default arguments other than fixing the
MS> binding-in-iteration

You can bind explicitly without default argument hack:
>>> f1, f2, f3 = [(lambda i: lambda: i)(i) for i in [1, 2, 3]]
>>> f1()
>>> f2()
>>> f3()

I think the same will apply to generator expression too.

Denis S. Otkidach      [ru]

More information about the Python-list mailing list