Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 通过比较两个列表创建布尔列表_Python_List_Filter_Boolean - Fatal编程技术网

Python 通过比较两个列表创建布尔列表

Python 通过比较两个列表创建布尔列表,python,list,filter,boolean,Python,List,Filter,Boolean,我有两个列表要比较。列表A包含我所有的文件名,列表B包含我想要的文件名 作为输出的List_C是一个与List_a长度相同的布尔列表。对于在List_B中找不到的文件显示false,对于在List_B中找到的文件显示true 这用于按布尔值筛选元素列表 # Load the Python Standard and DesignScript Libraries import sys import clr clr.AddReference('ProtoGeometry') from Autodesk

我有两个列表要比较。列表A包含我所有的文件名,列表B包含我想要的文件名

作为输出的List_C是一个与List_a长度相同的布尔列表。对于在List_B中找不到的文件显示false,对于在List_B中找到的文件显示true

这用于按布尔值筛选元素列表

# Load the Python Standard and DesignScript Libraries
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *

# The inputs to this node will be stored as a list in the IN variables.
dataEnteringNode = IN

List_A = IN[0]
List_B = IN[1]



OUT = List_C

A scenario

List_A = [x1, x2, x3, x4, x5]

List_B = [x2, x3]

List_C = [false, true, true, false, false]

这是映射,不是过滤,它是一个单行程序:

list(map(lambda x: x in List_B, List_A))
你可以用一个列表

[x in List_B for x in List_A]

但我个人发现在两种不同的意义上看x是令人困惑的。

使用列表理解:

List_C = [elem in List_B for elem in List_A]

这基本上等于一个for循环,对于List_a的每个元素,它将List_B中元素的结果附加到一个新列表。

这是一个注释。您试图解决它什么问题?您的解决方案的问题在哪里?您的解决方案->在哪里?所示代码中的导入和内容有什么好处?什么是[x1,x2,x3,x4,x5]-这些都是名称错误,因为它们是变量名,您没有在任何地方定义它们-对于[x2,x3]也是如此。请回答您的问题,提供一个最简单的例子和您的代码有问题。显示输入和输出以及不起作用的内容。谢谢