Python not a Very High-Level Language?

Gordon McMillan gmcm at hypernet.com
Mon Jan 3 21:22:27 EST 2000


Neel Krishnaswami wrote:

> 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.

Well, you could, but then you have to pass around the one-
and-only key to access the value. Seems more sensible, as 
Tres said, to pass around (key, value) instead and just forgo 
the hash.

make-mine-spam-eggs-and-spam-without-the-eggs-ly y'rs

- Gordon




More information about the Python-list mailing list