Tuples in Python - Hacker Rank Solution
Problem
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, , denoting the number of elements in the tuple.
The second line contains 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
Explanation
First we will take the input from the user of n and all elements in a lists.
Now we will converted this into tuple by the type conversion method.
And then using print it.
Solution
1 2 3 4 5 6 7 8 | if __name__ == '__main__': n = int(raw_input()) integer_list = map(int, raw_input().split()) lists = [] for i in integer_list: lists.append(i) print(hash(tuple(lists))) |