Issue 22973: hash() function gives the same result for -1 and for -2 argument (==-2) (original) (raw)

Issue22973

Created on 2014-12-01 11:18 by ardabro, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg231932 - (view) Author: ardabro (ardabro) Date: 2014-12-01 11:18
built-in hash() function cannot be effectively used for integers due to weird behavior for -1 argument: >>> hash(0) 0 >>> hash(-1) -2 # !!!!! >>> hash(-2) -2 >>> hash(-3) -3 >>>
msg231935 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2014-12-01 11:54
hash() is not defined to be unique, so you're always going to have collisions. The behavior of hash() for int that you're seeing is not a bug. There's some background here: http://stackoverflow.com/questions/10130454/why-do-1-and-2-both-hash-to-2-in-python
History
Date User Action Args
2022-04-11 14:58:10 admin set github: 67162
2014-12-01 11:54:13 eric.smith set status: open -> closedcomponents: + Interpreter Core, - Library (Lib)nosy: + eric.smithmessages: + resolution: not a bugstage: resolved
2014-12-01 11🔞28 ardabro create