2024-09-26 22:50:52 发布
网友
我想知道Python程序员将如何编写以下代码段:
for i in range(10): indexVector[i] = empAvg[i] + upperBound(t, pullCount[i])
这里t是一个常数。正如你所看到的,我习惯于C/C++风格的代码,但希望正确使用Python。你知道吗
t
如果要使用列表理解来创建indexVector(假设它在代码段中输入的10个索引之外没有任何其他值),可以使用-
indexVector
indexVector = [empAvg[i] + upperBound(t, pullCount[i]) for i in range(10)]
您可以zip列表empAvg和pullCount以元素方式遍历它们,而不需要i计数器,然后使用列表理解来创建indexVector
zip
empAvg
pullCount
i
indexVector = [emp + upperBound(t, pull) for emp, pull in zip(empAvg, pullCount)]
如果要使用列表理解来创建
indexVector
(假设它在代码段中输入的10个索引之外没有任何其他值),可以使用-您可以
zip
列表empAvg
和pullCount
以元素方式遍历它们,而不需要i
计数器,然后使用列表理解来创建indexVector
相关问题 更多 >
编程相关推荐