1
這是我輸入的樣子的一部分:比較列表或設置JSON對象
inputData=[]
inputData.append({"CustomerName": "CustomerA","State": "StateA","ItemNumber": "Item1"})
inputData.append({"CustomerName": "CustomerA","State": "StateA","ItemNumber": "Item2"})
inputData.append({"CustomerName": "CustomerB","State": "StateB","ItemNumber": "Item1"})
inputData.append({"CustomerName": "CustomerB","State": "StateB","ItemNumber": "Item2"})
inputData.append({"CustomerName": "CustomerX","State": "StateX","ItemNumber": "Item1"})
inputData.append({"CustomerName": "CustomerX","State": "StateX","ItemNumber": "Item2"})
這是我比較反對,以找出是否允許客戶購買的物品或不在名單。
allowedCustomers = ["CustomberA","CustomberB"]
我這是怎麼比較列表:
unauthorizedCustomers = list(set(inputData)-set(allowedCustomers))
使得比較只發生客戶名稱,但unauthorizedCustomers列表中有CustomerX
的完整的數據如何修改上面的語句?
[{"CustomerName": "CustomerX","State": "StateX","ItemNumber": "Item1"},
{"CustomerName": "CustomerX","State": "StateX","ItemNumber": "Item2"})]