例如,我有兩個list,其結果是調介面回傳值,我需要判斷兩個串列是否相等,串列里面嵌套字典,對于這樣復雜的資料,怎么判斷,試了多種方法,都不理想,請大佬指導,最好有代碼,下面兩個list1其實是一樣,只是個別數值位置不一樣
list1=[{u'resultCode': 1, u'data': {u'orderId': 56312886625L, u'areaId': 3921, u'townId': 21212, u'futureOrderLists': [{u'orderType': 0, u'sendpay': u'10000000000000000000000002000000030000000000000000000000000014000000000000000000000000000010000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', u'skuRelation': [[65982504902L, 65980453302L]], u'codDate': u'2020-07-77T00:00:00', u'detailList': [{u'skuId': 65982504902L, u'weight': 1.11, u'cid': 12241, u'storeId': 0, u'deliveryId': 0, u'bulk': 0.001, u'num': 1, u'cid2': 12222, u'skuUuid': u'1140160124794594795057926144', u'cidFirst': 12218}, {u'skuId': 65980453302L, u'weight': 1.0, u'cid': 11302, u'storeId': 1, u'deliveryId': 0, u'bulk': 0.001, u'num': 1, u'cid2': 830, u'skuUuid': u'1140160124794589200141602816', u'cidFirst': 9987}]}], u'tenantId': u'301', u'cityId': 2951, u'provinceId': 26}, u'resultMessage': u'\u8ba2\u5355(56312886625)\u5904\u7406\u6210\u529f', u'optSuccess': True, u'sourceType': 1}]
list2=[{u'resultCode': 1, u'data': {u'orderId': 56312886625L, u'areaId': 3921, u'townId': 21212, u'futureOrderLists': [{u'orderType': 0, u'skuRelation': [[65982504902L, 65980453302L]], u'codDate': u'2020-07-77T00:00:00', u'detailList': [{u'bulk': 0.001, u'skuId': 65982504902L, u'num': 1, u'weight': 1.11, u'cid': 12241, u'cid2': 12222, u'storeId': 0, u'deliveryId': 0, u'cidFirst': 12218, u'skuUuid': u'1140160124794594795057926144'}, {u'bulk': 0.001, u'skuId': 65980453302L, u'num': 1, u'weight': 1.0, u'cid': 11302, u'cid2': 830, u'storeId': 1, u'deliveryId': 0, u'cidFirst': 9987, u'skuUuid': u'1140160124794589200141602816'}], u'sendpay': u'10000000000000000000000002000000030000000000000000000000000014000000000000000000000000000010000000000000000000000000000000300000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'}], u'tenantId': u'301', u'cityId': 2951, u'provinceId': 26}, u'resultMessage': u'\u8ba2\u5355(56312886625)\u5904\u7406\u6210\u529f', u'optSuccess': True, u'sourceType': 1}]
uj5u.com熱心網友回復:
用for x in range(len(list1))回圈,再用len(x)遞進對比吧uj5u.com熱心網友回復:
def comp(dic1, dic2):
for k, v in dic1.items():
if k not in dic2.keys():
L.append({k: v})
if type(v) == list and type(v[0]) == dict:
comp(v[0], dic2[k][0])
elif type(v) == dict:
comp(v, dic2[k])
else:
if v not in dic2.values():
L.append({k: v})
L = []
comp(list1[0], list2[0])
print(L)
uj5u.com熱心網友回復:
樓上 comp方法,我拿出來單獨測驗了下,最終是回傳新的list,這個list保存的兩個list中存在差異的值?uj5u.com熱心網友回復:
對
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/33152.html
