1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| def main(): dict1 = { "family": { "grandfather": [ "John", { "father": "Michael", "kids": [ {"kid": ("Tom", 10, "M", "123 Street")}, {"kid": ("Lucy", 12, "F", "456 Street")} ] } ] } }
dict2 = { "family": { "grandfather": [ "John", { "father": "Michael", "kids": [ {"kid": ("Tom", 10, "M", "123 Street")}, {"kid": ("Lucy", 13, "F", "456 Street")} ] } ] } }
differences = compare_dicts(dict1, dict2) if not differences: print("没有差异") else: print("差异如下:") for diff in differences: print(diff)
if __name__ == "__main__": main()
|