[Python-ideas] PEP

Ethan Furman ethan at stoneleaf.us
Thu Mar 8 22:36:31 CET 2012

Mark Janssen wrote:
> On Thu, Feb 9, 2012 at 5:18 PM, Guido van Rossum wrote: 
>>         A dictionary would (then) be a SET of these. (Voila! things have
>>         already gotten simplified.)
>     Really? So {a:1, a:2} would be a dict of length 2? 
>>          Eventually, I also think this will seque and integrate nicely
>>         into Mark Shannon's "shared-key dict" proposal (PEP 412).
> 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, but I wonder if anyone's noticed any problems with this, and 
> whether the hash collision problems could be solved by removing this??   
> Does anyone even use this functionality -- of a *variable* (not a 
> string) as a dict key?

Um, yes?  As in, most of the time.  Don't you?

And Python uses whatever object the name is bound to:

--> huh = 5
--> d = {}
--> d[huh] = 'hrm'
--> d
{5: 'hrm'}


More information about the Python-ideas mailing list