The Python Oracle

Why is CPython's hash(-1) != -1

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Switch On Looping

--

Chapters
00:00 Question
00:45 Accepted answer (Score 5)
01:05 Thank you

--

Full question
https://stackoverflow.com/questions/1687...

Accepted answer links:
http://effbot.org/zone/python-hash.htm

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #hash #cpython

#avk47



ACCEPTED ANSWER

Score 5


From http://effbot.org/zone/python-hash.htm:

The hash value -1 is reserved (it’s used to flag errors in the C implementation). If the hash algorithm generates this value, we simply use -2 instead.