Python program to find hash from a given tuple

PythonServer Side ProgrammingProgramming

Suppose we have a tuple. There are few numbers are present. We have to find the hash value of this tuple by using hash() function. This is a built-in function. The hash() function can work on some datatypes like int, float, string, tuples etc, but some types like lists are not hashable. As lists are mutable in nature, we cannot hash it. This hash value is used to map other values when we use dictionary.

So, if the input is like t = (2,4,5,6,7,8), then the output will be -1970127882925375109

To solve this, we will follow these steps −

  • take the tuple as input

  • call hash function and pass the tuple into it hash(tuple)

Example

Let us see the following implementation to get better understanding

def solve(t):
   return hash(t)

t = (2,4,5,6,7,8)
print(solve(t))

Input

(2,4,5,6,7,8)

Output

-6569923111468529526
raja
Updated on 11-Oct-2021 10:26:56

Advertisements