How to determine if something is hashable?

Andrew Post apost at
Mon Jun 25 19:48:55 CEST 2001


I want to write a function that takes a list of keys and a list of 
values and returns a hash. I want to test, however, that all of the 
items in the list of keys are hashable. How do I do this? The only way 
that I've come up with so far is to do:

     myDict[ keyList[ i ] ] = valList[ i ]
except (TypeError):
     print keyList[ i ], 'is not hashable'

TypeError isn't specific to finding a non-hashable key, though, right?


Andrew Post

More information about the Python-list mailing list