我试图将regex findall()函数的结果传递给一个列表。我使用的代码如下:
#iterate DoL, find fobIDs and use to find edgeloop IDs
for key, val in DoL.items():
fobId = val["FaceOuterBound"]
edgeloop_txt = re.findall(r'\n#'+str(fobId)+r'\D*#(\d+).*;', text)
edgeloops = [int(edgeloop) for edgeloop in edgeloop_txt]
print(edgeloops)
for循环在字典中迭代,每次都更改fobId
,每次都生成不同的匹配。当前输出如下所示:
[159]
[328]
[37]
[18]
...
但是,我希望它看起来像这样:
[159, 328, 37, 18,....]
我猜这与for循环每次更改变量edgeloop_txt
有关,但我不确定如何避免这种情况
现在,您正在创建一个新数组,并且每次通过循环打印它。尝试以下操作:
这将循环您的项目,不断地添加到
total_array
,并在循环完成时打印整个数组相关问题 更多 >
编程相关推荐