Skip to content

Instantly share code, notes, and snippets.

@martinvol
Last active August 12, 2018 21:45
Show Gist options
  • Save martinvol/4dae0dc88c40efb78650c5bba48441a3 to your computer and use it in GitHub Desktop.
Save martinvol/4dae0dc88c40efb78650c5bba48441a3 to your computer and use it in GitHub Desktop.
How to hash non-hashable and mutable objects in Python
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