Issue
I am trying to solve the below problem:
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).
I am using python 3. My code is
if __name__ == '__main__':
n = int(input())
integer_list = map(int, input().split())
t = tuple(integer_list)
print(hash(t))
The expected output is 3713081631934410656 but I am getting -3550055125485641917. I think my code is correct. Why am i getting a different output?
If I am using Pypy3, I am getting the correct output 3713081631934410656 but not with Python 3
Solution
Python doesn't promise that tuple hashing will produce any particular output. There is no such thing as the "correct" output for hash(some_tuple)
. The tuple hash implementation is free to change, and it has changed in Python 3.8.
Your assignment was likely written for a different Python version than the one you're testing on, without consideration of the fact that the tuple hash algorithm is an implementation detail.
Answered By - user2357112
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.