数组 = 某种具有 3 列和无限数量的行且其中包含数据的列表。
Volume = array[0][2]
counter = 0
for i in array:
if Volume == array[i][2]: #<------ why is this line a problem?
counter += 1
这是一个典型的错误。i
在你的情况下已经是一个元素array
(即另一个列表),not的索引array
(not an int
), so
if Volume == i[2]:
counter += 1
您可以检查Python教程 https://docs.python.org/3.4/tutorial/controlflow.html#for-statements。另外,尝试这样做:
for i in array:
print (i)
看看你会得到什么!
另外我建议坚持命名约定:变量通常是小写的(volume
, not Volume
)。在这种情况下i
具有误导性。row
or elem
会更合适。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)