[Python-ideas] PEP

Masklinn masklinn at masklinn.net
Thu Mar 8 22:59:31 CET 2012

On 2012-03-08, at 22:08 , Mark Janssen wrote:
> I just noticed something in Guido's example.  Something gives me a strange
> feeling that using a variable as a key doesn't smell right.  Presumably
> Python just hashes the variable's id, or uses the id itself as the key

Python calls ``hash`` on the object and uses the result.

> , but
> I wonder if anyone's noticed any problems with this, and whether the hash
> collision problems could be solved by removing this??

No. Not that it makes sense, people could ask for object hashes on
their own and end up with the same result.

>   Does anyone even
> use this functionality -- of a *variable* (not a string) as a dict key?

What you're asking does not make sense, the dict key is not the name
but whatever object is bound to the name.

And yes I've used non-string objects as names before: tuples, frozensets,
integers, my own objects, …

More information about the Python-ideas mailing list