Created
July 24, 2013 07:38
-
-
Save signalpillar/6068700 to your computer and use it in GitHub Desktop.
Below you will find interesting fact of how python works when collision happens, CPython ( & Pypy & Jython) behaviour in such case is called **probing** http://stackoverflow.com/questions/327311/how-are-pythons-built-in-dictionaries-implemented
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| >>> dict = {1: 2} | |
| >>> dict[1] = 3 | |
| >>> dict | |
| {1: 3} | |
| >>> class A: | |
| ... def __hash__(self): | |
| ... return 1 | |
| ... | |
| >>> class B: | |
| ... def __hash__(self): | |
| ... return 1 | |
| ... | |
| >>> dict = {A(): 2} | |
| >>> dict | |
| {<__main__.A instance at 0x1043508c0>: 2} | |
| >>> dict[B()] = 3 | |
| >>> dict | |
| {<__main__.A instance at 0x1043508c0>: 2, <__main__.B instance at 0x104350950>: 3} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment