Ravindu Shantha
Ravindu Shantha

Reputation: 49

Python Hash function and Hash Object

What is the different between hashable and hashobject in python?

Upvotes: 0

Views: 1231

Answers (1)

SeedofWInd
SeedofWInd

Reputation: 147

  • Hashable

    • In general means an object has a hash value that never changes in its lifetime and can be compared to other objects. Thanks to those two features, a hashable object can be used as a key in a generic hash map
    • in python mmutable built-in objects are hashable while mutable containers (such as lists or dictionaries) are not. User-defined objects are by default hashable
  • Hashtable

    • in general, hash table (hash map) is a data structure used to implement an associative array, a structure that can map keys to values. Each key given a hash value through hash function for lookup
    • in python, dictionary is an implementation of hashtable
  • hash() in python

    • hash is a hash function that gives you a hash value (for the key inputed)
      In [1]: hash ('seed_of_wind')
      Out[1]: 8762898084756078118
      
    • As mentioned already, this distinctive 'id' is very useful for look up
    • in theory, a distinctive key will generate a distinctive hash value

By hash object, do you mean by hashable object? If so, it is covered above

Upvotes: 2

Related Questions