I have these two states that represent the same state, but with changed order, with Python:
state1 = [ [1,5,6], [8,2,1] ]
state2 = [ [8,2,1], [1,5,6] ]
How can I hash these two states to be able to compare them? (state1 == state2)
>Solution :
I would do it like this:
>>> from collections import Counter
>>> def my_hash(state):
... counter = Counter([tuple(x) for x in state])
... items = frozenset(counter.items())
... return hash(items)
...
>>> my_hash(state1) == my_hash(state2)
True