需求是对两个嵌套数字进行对比,判断两个数组的内容是否是一样的。
[{'type': 4, 'pos': [403, 323, 563, 352], 'content': '0'}, {'type': 4, 'pos': [492, 572, 609, 630], 'content': '0'}, {'type': 4, 'pos': [412, 740, 532, 798], 'content': '0'}, {'type': 4, 'pos': [112, 807, 178, 865], 'content': '0'}, {'type': 4, 'pos': [82, 1060, 1107, 1432], 'content': '1'}, {'type': 3, 'pos': [82, 1060, 1107, 1432], 'content': '-2'}, {'type': 7, 'pos': [], 'content': '09.07'}, {'type': 2, 'pos': [], 'content': '2'}]
[{'type': 4, 'pos': [112, 807, 178, 865], 'content': '0'}, {'type': 4, 'pos': [82, 1060, 1107, 1432], 'content': '1'}, {'type': 3, 'pos': [82, 1060, 1107, 1432], 'content': '-2'}, {'type': 4, 'pos': [403, 323, 563, 352], 'content': '0'}, {'type': 4, 'pos': [492, 572, 609, 630], 'content': '0'}, {'type': 4, 'pos': [412, 740, 532, 798], 'content': '0'}, {'type': 7, 'pos': [], 'content': '09.07'}, {'type': 2, 'pos': [], 'content': '2'}]
大概有以下几种思路
三种方法都试了:
strA = response.json["data"]["answerSheets"]["30371513"]["pages"]["1"]
strB = [{"type":4,"pos":[112,807,178,865],"content":"0"},{"type":4,"pos":[82,1060,1107,1432],"content":"1"},{"type":3,"pos":[82,1060,1107,1432],"content":"-2"},{"type":4,"pos":[403,323,563,352],"content":"0"},{"type":4,"pos":[492,572,609,630],"content":"0"},{"type":4,"pos":[412,740,532,798],"content":"0"},{"type":7,"pos":[],"content":"09.07"},{"type":2,"pos":[],"content":"2"}]
res = True
diff = []
for i in range(0, len(strA)):
if(strA[i] not in strB):
diff.append(strA[i])
res = False