简体   繁体   English

如何检查二维列表是否包含部分包含另一个列表的列表

[英]How to check if a 2D list contains a list that partly contains another list

I'm trying to find out if my Tabu list (2D) contains a list that partly contains another list.我试图查明我的Tabu列表 (2D) 是否包含一个列表,该列表部分包含另一个列表。

Like:喜欢:

Tabu = [[1, 2, 3], [3, 2, 1, 0]]
Test = [3, 2, 1]
Test2 = [1, 3, 2]

Here Tabu contains a list: [3, 2, 1, 0] that contains [3, 2, 1] , so Tabu contains Test, but doesn't contain Test2 as there are no lists in Tabu that contain [1, 3, 2] in this order.这里 Tabu 包含一个列表: [3, 2, 1, 0]包含[3, 2, 1] ,因此 Tabu 包含 Test,但不包含 Test2,因为 Tabu 中没有列表包含[1, 3, 2]按此顺序。

Note: All values of Test must be in a sublist of Tabu to pass.注意:Test 的所有值必须在 Tabu 的子列表中才能通过。 Changing the lists to sets is not an option.将列表更改为集合不是一种选择。 There are no repeating values in Test and only two seperate lists can contain the same value in Tabu. Test 中没有重复值,Tabu 中只有两个单独的列表可以包含相同的值。

Edit: More info and clarification编辑:更多信息和说明

you need to iterate through the Tabu and check if all element of the Test list are in the sublist of Tabu您需要遍历 Tabu 并检查 Test 列表的所有元素是否都在 Tabu 的子列表中

>>> Tabu = [[1, 2, 3], [4, 5, 6, 0]]
>>> Test = [4, 5, 6]
>>> 
>>> result = any(all(i in sublist for i in Test) for sublist in Tabu)
>>> result
True
>>> 

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

相关问题 检查 2d 列表中的任何嵌套列表是否都包含一个值并且不包含另一个值 - Check if any nested list within a 2d list both contains one value and does not contain another 检查二维列表中的列是否包含相同的值 - Check if a column in a 2D list contains the same values 检查列表是否在python中包含另一个列表 - Check if list contains another list in python 检查列表数组是否包含另一个列表中的元素 - Check if list array contains element in another list 检查列表中是否包含其他列表中的项目 - Check if List Contains Items From Another List 如何检查一个列表是否包含另一个不同值的列表 - How to check if a list contains another list of different values 如何检查 Python 列表是否包含另一个列表的重复项未忽略的元素 - How to Check if Python List Contains Elements of Another List Duplicates Not Ignored 如何检查一个列表是否包含另一个列表的所有元素,包括重复项 - How to check if a list contains all the elements of another list INCLUDING duplicates 如何检查一个列表是否包含另一个列表的 2 个元素? - How do I check if one list contains 2 elements of another list? 考虑顺序如何检查列表(字符串)是否包含另一个列表(字符串) - How to check if a list (string) contains another list (string) considering order
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM