Created
April 10, 2020 07:33
-
-
Save cereme/6da5b2e4264d1ec7d7cae361b973e50a to your computer and use it in GitHub Desktop.
hashable?
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
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