Why is lambda allowed as a key in a dict?

Iain King iainking at gmail.com
Tue Mar 10 11:09:53 CET 2009


On Mar 10, 6:38 am, Daniel Fetchinson <fetchin... at googlemail.com>
wrote:
> On 3/9/09, bearophileH... at lycos.com <bearophileH... at lycos.com> wrote:
>
> > See here Daniel Fetchinson:
>
> >http://groups.google.com/group/comp.lang.python/browse_thread/thread/...
>
> > But be quite careful in using that stuff, it has some traps.
>
> Thanks a lot for all the helpful replies!
> Yes, I should name the unnamed lambda function, or better, just use 'def'.
>
> Cheers,
> Daniel
>
> --
> Psss, psss, put it down! -http://www.cafepress.com/putitdown


Sort of tangenitally; is there any real difference between the outcome
of the two following pieces of code?

a = lambda x: x+2

def a(x):
    return x+2

Iain



More information about the Python-list mailing list