Python not a Very High-Level Language?

Neel Krishnaswami neelk at brick.cswv.com
Mon Jan 3 20:22:15 EST 2000


Tres Seaver <tseaver at aftershock.neosoft.com> wrote:
> 
> What reasonable use can you propose for an associative container
> which allows mutable keys?  You might as well revert to a list of
> (key,value) pairs, since you're going to do a linear search on each
> lookup anyway if the keys are allowed to change.

You can compute the hash function using the object's identity, rather
than its value. IOW, hash on the object's address. Then you can mutate
the contents of the object as needed and still access the hash. In
fact, I believe this is the default behavior for Common Lisp hash
tables (though of course you can create hash tables with different
hash functions).

This should be even easier in Python than in Lisp, since objects are
guaranteed not to be relocated, so a garbage collection can't force
rehashing.


Neel



More information about the Python-list mailing list