I have:
tuple1 = token1, token2
tuple2 = token2, token1
for tuple in [tuple1, tuple2]:
if tuple in dict:
dict[tuple] += 1
else:
dict[tuple] = 1
However, both tuple 1 and tuple2 are getting the same counts. What is a way to hash a group of 2 things such that order matters?
Order is taken into account when hashing:
This assumes that the objects themselves have unique hashes. Even if they don’t, you could still be OK when using it in a dictionary (as long as the objects themselves aren’t equal as defined by their
__eq__method):Note that due to hash collisions, this dict is likely to be less efficient than another dict where there aren’t hash collisions 🙂