Last active
August 12, 2018 21:45
-
-
Save martinvol/4dae0dc88c40efb78650c5bba48441a3 to your computer and use it in GitHub Desktop.
How to hash non-hashable and mutable objects in Python
This file contains 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 Node: | |
# ... | |
def __hash__(self): | |
return id(self) | |
my_node = Node() | |
my_hash = {my_node: "It's there!"} | |
print(my_hash[my_node]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment