python - 如何在python中找到一个列表而不是另一个列表的子列表?
问题描述
我需要比较两个基本上是列表列表的列表,找出存在于一个列表中但不存在于其他列表中的子列表。子列表的排列也不考虑即['a','b'] = ['b,'a']。这两个列表是
List_1 = [['T_1','T_2'],['T_2','T_3'],['T_1','T_3']]
List_2 = [['T_1','T_2'],['T_3','T_1']]
输出列表应该是
out_list = [['T_2','T_3']]
解决方案
对于两个元素子列表,这应该足够了:
[x for x in List_1 if x not in List_2 and x[::-1] not in List_2]
代码:
List_1 = [['T_1','T_2'],['T_2','T_3'],['T_1','T_3']]
List_2 = [['T_1','T_2'],['T_3','T_1']]
print([x for x in List_1 if x not in List_2 and x[::-1] not in List_2])
推荐阅读
- c# - 重新加载/重新启动 ASP.NET Core 2.1 Web 应用程序
- javascript - 动态选择选项列表的vue渲染
- java - 输出问题,用户输入通过 void 函数(Caesar's Cipher,Java,swing)
- prolog - Prolog 中的无损通用量化
- android - Firebase 身份验证 - 发生网络错误(例如超时、连接中断或无法访问主机)
- python - jinja2.exceptions.TemplateNotFound: home.html
- php - WHERE 子句不显示数据
- python - Heroku 上托管的简单烧瓶应用程序的身份验证
- java - 如何在 VSCode 中为 Bamboo Specs Java 启用 Intellisense
- c# - REST API HttpPost 它让我失望了