Skip to content

Instantly share code, notes, and snippets.

@cereme
Created April 10, 2020 07:33
Show Gist options
  • Save cereme/6da5b2e4264d1ec7d7cae361b973e50a to your computer and use it in GitHub Desktop.
Save cereme/6da5b2e4264d1ec7d7cae361b973e50a to your computer and use it in GitHub Desktop.
hashable?
class HashableTrap:
def __init__(self, data):
self.data = data
def __repr__(self):
return "EvenReprIsSame"
def __hash__(self):
return 1
a = HashableTrap(1)
b = HashableTrap(2)
print(a, b) # EvenReprIsSame EvenReprIsSame
print(hash(a), hash(b)) # 1 1
d = {}
d[a] = 10
print(d) # {EvenReprIsSame: 10}
d[b] = 20
print(d) # {EvenReprIsSame: 10, EvenReprIsSame: 20}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment