Home > other >  Python2 how to determine the two complex list are equal, such as online
Python2 how to determine the two complex list are equal, such as online

Time:12-05

I have two list, for example, the result is a callback interface to return the value, I need to determine whether two lists are equal, nested list dictionary, for such complex data, how to judge, tried a variety of methods are not ideal, please leaders guidance, had better have the code, the following two list1 in fact is the same, just different individual numerical position
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}]

CodePudding user response:

Used for x in the range (len (list1) cycle, reoccupy len (x) progressive contrast

CodePudding user response:

 def comp (dic1, dic2) : 
For k, v in dic1. The items () :
If not in dic2. K keys () :
L.A. ppend (} {k: v)
If the type (v)==list and type (v [0])==dict:
Comp (v [0], dic2 [k] [0])
Elif type (v)==dict:
Comp (v, dic2 [k])
The else:
If v not in dic2. Values () :
L.A. ppend (} {k: v)

L=[]
Comp (list1 [0], list2 [0])
Print (L)

CodePudding user response:

Comp upstairs, I take out separate tested, finally is to return a new list, this list of the value of the difference in the two list?

CodePudding user response:

reference weixin_39881503 reply: 3/f
comp way upstairs, I take out separately tested, finally is to return a new list, this list of the value of the difference in the two list?

right
  • Related