我有可能包含其他字典或列表的嵌套字典。我需要能够比较这些字典的列表(或集合,真的)以表明它们是相等的。
列表的顺序不统一。通常,我会将列表转换为集合,但这是不可能的,因为有些值也是字典。
a = {'color': 'red'}
b = {'shape': 'triangle'}
c = {'children': [{'color': 'red'}, {'age': 8},]}
test_a = [a, b, c]
test_b = [b, c, a]
print(test_a == test_b) # False
print(set(test_a) == set(test_b)) # TypeError: unhashable type: 'dict'
Run Code Online (Sandbox Code Playgroud)
有没有一种很好的方法来解决这个问题以显示test_a与test_b?