Instagram
youtube
Facebook
Twitter

Python Tuples HackerRank Solution


In this tutorial, we are going to solve the python tuples problem from hackerrank.

Task

Given an integer, n, and n space-separated integers as input, create a tuple, t, of those n integers. Then compute and print the result of hash(t).

Note: hash() is one of the functions in the __builtins__ module, so it need not be imported

Input Format

The first line contains an integer, n, denoting the number of elements in the tuple.

The second line contains n space-separated integers describing the elements in tuple t.

Output Format

Print the result of hash(t).

Sample Input 0

2

1 2

 

Sample Output 0

3713081631934410656

 

Solution: 

if __name__ == '__main__':

    n = int(input())

    Tuple1 = map(int, input().split())

    t = tuple(Tuple1)

    print(hash(t));

    

(we have used pypy3 language to solve this problem)

Steps Used in solving the problem -

Step 1: First, n had taken integer type input.

Step 2: then, we created a list containing n numbers of integers.

Step 3: After this, we changed our list into a tuple.

Step 4: in the last step we used the hash module and printed it.