Fahim February 2016

How hash() function works in Python?

I cannot understand how hash() works in Python and in which cases would we need it.

a = int(raw_input())
b = tuple(map(int,raw_input().split()))
print(hash(b))

Here is a simple example using hash() and I would like someone to explain it to me.

Answers


sorin February 2016

hash is implemented in Python the same way as in other languages, nothing special about it.

Imagine that hash() takes an object and generates a really-big-number that is used in a way similar to a fingerprint, to quickly identity its owner.

Hashes are not universal, which means that the final result depends on the implementation, but you should not care about this too much.

Post Status

Asked in February 2016
Viewed 1,541 times
Voted 8
Answered 1 times

Search




Leave an answer