python中具有列表输入的函数

2024-04-20 15:20:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个函数,例如:

RotateElement (doc, lmnt_id, axis, angle)

lmnt_idaxisangle是以列表形式出现的输入。例如:

axis = [line1, line2, line3]
angle = [20, 25, 30]
lmnt_id = [1, 2, 3]
doc is a constant value

我如何调用这个函数以便它遍历输入。我希望它第一次运行时使用第1行、第20行和第1行,第二次运行时使用第2行、第25行和第2行,以此类推。我试过这个,但只运行过一次:

for i in lmnt_ids:
    lmnt_id = i
    for j in axises:
        axis = j
        result.append(ElementTransformUtils.RotateElement (doc, lmnt_id, axis, angle))

谢谢你!你知道吗


Tags: 函数inid列表fordocis形式
1条回答
网友
1楼 · 发布于 2024-04-20 15:20:24

看起来你想要:

for axis_, angle_, lmnt_id_ in zip(axis, angle, lmnt_id):
    result.append(ElementTransformUtils.RotateElement(doc, lmnt_id_, 
                                                      axis_, angle_))

^{}将匹配这三个列表,并将每个列表的第n个值依次分配给循环变量

相关问题 更多 >