I need to store a set of lists hashed by identity: two lists are equal iff they are the same object.
Not only does using tuples not make much sense semantically, but I also need to mutate the lists sometimes (append a few elements to the end every once in a while), so I can't use a tuple at all.
How do I store a hash set of lists hashed by identity in Python?
Use dict instead of set, and let the id of the list be the key:
dct[id(lst)] = lst
Test for existence of list in the "set" using id(lst) in dct.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With