python-3.x - 如何比较嵌套列表并将不匹配项追加到python3中的新列表?
问题描述
I want to compare 2 nested list. compare index 1 of list 1 with list 2 index 1 and appedn list 1 , list 2 to the new list. in python3
l1 = [['a','bat','c'], ['a','doll','c']]
l2 = [['a','flowers','c'],['a','god','c'],['a','bat','c']]
output = []
for i in l1:
for j in l2:
if i[1] != j[1]:
output.append(j)
break
print(output)
Expected Output:
[['a','doll','c'] ,['a','flowers','c'],['a','god','c']
我想比较 2 个嵌套列表。比较列表 1 的索引 1 与列表 2 的索引 1 并将列表 1 和列表 2 添加到新列表。在python3中
解决方案
推荐阅读
- database - Deno 使用 $lookup 和 $project 与 mongoDB 聚合
- javascript - Reactjs - 加载翻译文件时出错
- typescript - 在 Cypress 中存储访问令牌 - Cypress OAuth 2.0
- google-api - 访问整个 gsuite 域日历事件
- c# - ToolStripLabel 未使用 PropertyBinding 更新应用程序设置
- python - Django:使用公共外键链接两个模型
- python - 审核 url 为允许的方案打开。允许使用文件/或自定义方案通常是出乎意料的
- php - 在不安装 MS SQL 驱动程序的情况下使用 php_pdo_sqlsrv 需要哪些 dll
- node.js - NodeJS WebSocket 多路径
- neo4j - 在 neo4j 中使用 gds.alpha.graphSage.stream 时出错