I think the easiest way is to use lists.
group_1 = my_dict_1.values() group_2 = my_dict_2.values()
Your comparison will not be as simple as if it were an order, or if the values โโwere hashed, but the following should work:
def contain_the_same(group_1, group_2): for item in group_1: if item not in group_2: return False else: group_2.pop(group_2.index(item)) if len(group_2) != 0: return False return True
This should be able to handle non-removable objects simply:
>>> contain_the_same([1,2,3], [1,2,3]) True >>> contain_the_same([1,2,3], [1,2,3,4]) False >>> contain_the_same([1,2,[3,2,1]], [1,2,[3,2,1]]) True >>> contain_the_same([5,1,2,[3,2,1,[1]]], [1,[3,2,1,[1]],2,5]) True
Caution: this will return false if there are duplicates in one list but no other. This will require some modification if you want to make it valid.
Edit: Even easier:
sorted(my_dict_1.values()) == sorted(my_dict_1.values())
It looks like it's twice as fast as my contain_the_same function:
>>> timeit("contain_the_same([5,1,2,[3,2,1,[1]]], [1,[3,2,1,[1]],2,5])", "from __main__ import contain_the_same", number=10000)/10000 8.868489032757054e-06 >>>timeit("sorted([5,1,2,[3,2,1,[1]]]) == sorted([1,[3,2,1,[1]],2,5])", number=10000)/10000 4.928951884845034e-06
Although it would not be so easy to extend to the case when duplicates are allowed.