In message <mailman.1990.1256441598.2807.python-l...@python.org>, Michal 
Ostrowski wrote:
> def MakeLambdaBad():
>   a = []
>   for x in [1,2]:
>      a.append(lambda q:  x + q)
>   return a

Here's another form that should work:

    def MakeLambdaGood2() :
        a = []
        for x in [1, 2] :
            a.append((lambda x : lambda q : x + q)(x))
        return a

It's all a question of scope.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to