Modules are hashable?!

Jason Lai jmlai at uci.edu
Fri Sep 3 06:23:49 CEST 2004


Maurice LING wrote:
> 
> The idea that I get from reading this thread is that objects that can be 
> type compared (comparing the contents) are not hashable, and they are 
> list, strings, tuples and dictionary. Is there any others that fall into 
> this category? Is there any way to make them hashable?

Well, strings and tuples are immutable, so they provide a hash function 
(since it's safe to hash them by contents; the contents are pointers 
that don't change.) Anything that provides a hash function can be 
hashed. You could theoretically create a new list type that works 
exactly like a normal list, but hashes based on ID.

> 
> Hashable objects, on the other hand, are hashed based on say, the 
> pointer address pointing the object or an identifier in the Python VM 
> symbol table or something. It's like to say that when you hash a human, 
> you get the name and not the physical dimensions of the person. The 
> person can grow fat or slim down, but the name is still the same.
> 
> Maurice

Heh, like giving every person a unique govt-assigned ID number. You 
could have two people who are exactly alike -- cloned atom-by-atom, or 
something -- but they wouldn't have the same ID. And the term "hashing" 
originates from chopping things up, so hashing humans wouldn't be a good 
idea :P

  - Jason Lai



More information about the Python-list mailing list