Why is lambda allowed as a key in a dict?

Craig Allen callen314 at gmail.com
Tue Mar 10 19:23:54 EDT 2009


> I think the point is that function objects compare by object identity,
> so the two lambdas you use above are not equal even though they have the
> same code.

it raises an interesting question about why doesn't it.  I can think
of practical answers to that, obviously, but in principle, if a
function compiles to exactly the same byte code, you obviously do not
need two copies of it, and like strings shouldn't an identical
function have the same id?

This is merely philosophical, I don't see the value in making this so
(a slight optimizaton and perhaps better conformity to other python
features), but I do think it's an interesting question.

cheers.



More information about the Python-list mailing list