Is and if so how, is it possible to compare the equality of an unordered list o dictionaries with dynamic keys & values?
dict_list_1 = [ {'a': 'b'}, {'c': 'd'} ]
dict_list_2 = [ {'c': 'd'}, {'a': 'b'} ]
dict_list_3 = [ {'c': 'd'}, {'d': 'c'} ]
where dict_list_1
and dict_list_2
should be considered equal and dict_list_3
shouldnt be equal to any of the other 2
The keys (and values) of the dicts are dynamic so sorting gets a bit harder
Current code for comparing equality of 2 dicts:
for a in dict_1.keys():
try:
if dict_1[a] != dict_2[a]:
return False
# recursive in case of dict within dict
if not equal_dict_values(dict_1[a], dict_2[a]):
return False
except KeyError:
return False
return True
But I'm not quite sure how to approach the unordered list of dicts problem.