Skip to content

Instantly share code, notes, and snippets.

@signalpillar
Created July 24, 2013 07:38
Show Gist options
  • Select an option

  • Save signalpillar/6068700 to your computer and use it in GitHub Desktop.

Select an option

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
>>> 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