[python-nl] lambda rewrite question

Floris van Manen vm at klankschap.nl
Wed Jun 29 16:01:38 CEST 2011


For those of you who know everything about the basic python syntax & semantics ...
I get stuck in a simple context issue (i think)


this version works, it return the stored float value

def rewrite( d ):
    for key in d:
        for k in d[key]['next']:
            c = float(d[key]['next'][k]['prob'])
            d[key]['next'][k]['prob'] = c
    return d



this doesn't
if i call the function it will return a (random?) identical value for all stored lambda functions.

def rewrite( d ):
    for key in d:
        for k in d[key]['next']:
            c = float(d[key]['next'][k]['prob'])
            d[key]['next'][k]['prob'] = lambda : c
    return d


There is most likely a reason to it.
Can someone explain me what that reason is ?

Thanks!
.Floris




More information about the Python-nl mailing list