【发布时间】:2021-11-29 21:01:31
【问题描述】:
我正在解决 Kaggle 列表和理解模块,并得到以下代码的错误答案:
def elementwise_greater_than(L, thresh):
"""Return a list with the same length as L, where the value at index i is
True if L[i] is greater than thresh, and False otherwise.
>>> elementwise_greater_than([1, 2, 3, 4], 2)
[False, False, True, True]
"""
for num in L:
if L[num] > thresh:
L[num] = True
else:
L[num] = False
return L
pass
它给出以下输出:[False, False, 3, True]
if L[num]>thresh 有一个错误,但我不明白是什么。
【问题讨论】:
标签: python-3.x list