some_list = [[app_num, product, prod_size, prod_amt]]
other_list = [[app_num, product, prod_size, prod_amt]]
我有兩個列表。 app_num的some_list和other_list之間沒有匹配。但是,對於other_list中的給定app_num,產品prod_size_和prod_amt可能與some_list中給定app_num中的相同。我正在嘗試創建一個與some_list相同的final_some_list,除了它已從some_list中刪除任何列表元素(如果該列表元素具有相同的product,prod_size和prod_amt作爲other_list中的元素)。Python - 比較兩個嵌套列表並寫入第三個嵌套列表
我已經嘗試嵌套for循環,列表理解(下面是許多失敗嘗試的一些例子)。
final_some_list = [app for app in some_list for other_app in other_list
if not app[1] == other_app[1] and app[2] == other_app[2] and app[3] ==
other_app[3]
final_some_list = [app for app in some_list for other_app in other_list
if not app[1] and app[2] and app[3] == in other_app
你能分享輸入的實例和期望的輸出,使它讓任何人都更容易理解你的問題? –