简体   繁体   English

检查列表的元素是否是另一个列表的元素的子集

[英]To check whether elements of a list is a subset of elements of another list

Here I am trying to check whether elements of 'b' that are [1,3],[1,5],[3,7],[5,7],[6,9],[8,10] are subsets of elements of 'a' that are [1,3,5,7] and [6,8,9,10]. 在这里,我试图检查'b'的元素是否为[1,3],[1,5],[3,7],[5,7],[6,9],[8,10] 'a'的元素的子集为[1、3、5、7]和[6、8、9、10]。 If any element of b is subset of any element of a then it gets removed from b. 如果b的任何元素是a的任何元素的子集,则将其从b中删除。

     a = [[1, 3, 5, 7],[6, 8, 9, 10]]
     b = [[1, 3], [1, 5],[10, 11],[6, 9],[8, 10]]

If any element of 'b' is subset of any element of 'a' then it gets removed from b. 如果“ b”的任何元素是“ a”的任何元素的子集,则将其从b中删除。 That means the new b should be :- 这意味着新的b应该是:

     b = [[10,11]]

如果要进行集合操作,请使用python的集合数据类型,该数据类型具有issubset()方法。

b = [x for x in b if not any(set(x).issubset(y) for y in a)]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查列表是否以另一个列表的元素开头 - Check whether a list starts with the elements of another list 检查具有列表值的列的元素是否存在于另一个列表中 - Check whether the elements of a column with list values are present in another list 检查列表是否以另一个列表的元素开头,如果找到,则将两个值一起返回 - Check whether a list starts with the elements of another list and if found return both the values together 如何检查另一个字典列表中是否存在词典项的子集? - How to check whether a subset of dictionary items exists in another list of dictionaries? 检查列表元素是否存在于另一个列表的元素中 - check if element of list is present in elements of another list 检查另一个列表中一个列表中的元素 - Check for elements in one list from another list 最佳检查列表的元素是否在 python 的另一个列表中 - Optimal check if the elements of a list are in another list in python 尝试根据元素是否在 Python 中的另一个列表中来过滤一个列表 - Trying to filter one list according to whether elements are in another list in Python Python - 评估列表子集的元素 - Python - evaluate elements of a list subset 如何检查python列表中的最后三个元素-它们是否是整数? - How to check last three elements from a python list - whether they are integer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM