Sort by

recency

|

1767 Discussions

|

  • + 0 comments

    I can't understand what is wrong with my code? if name == 'main': n = int(input()) a=input().split() tup=tuple(a) print(hash(tup))

  • + 0 comments

    Yes HR need to fix this. Output is very specific to python version.

    Proof: $python3 Python 3.10.12 (main, Jan 17 2025, 14:35:34) [GCC 11.4.0] on linux Type "help", "copyright", "credits" or "license" for more information.

    t=(1,2) print(hash(t)) -3550055125485641917

    $ python2 Python 2.7.18 (default, Dec 9 2024, 18:47:23) [GCC 11.4.0] on linux2 Type "help", "copyright", "credits" or "license" for more information.

    t=(1,2) print(hash(t)) 3713081631934410656

  • + 1 comment

    dont waste your time, knocking head for this problem. The solution is designed based on python 2 , and hash function is giving different output in python 2 and 3, so solve it in python 2 only.

  • + 0 comments

    if name == 'main': n = int(raw_input()) integer_list = map(int, raw_input().split())

    elements=tuple(integer_list)
    result=hash(elements)
    

    print(result)

  • + 0 comments

    You must solve this in Python 2 to get the correct answer

    There are several key differences between the hash() function in Python 2 and Python 3:

    Python 2: Used a non-cryptographic hash algorithm called FNV (Fowler-Noll-Vo) which was fast but vulnerable to collisions.

    Python 3: Uses a more secure algorithm called SipHash which is designed to be resistant to hash collision attacks.