我正在尝试检查某些元素是否在列表中,并执行数值更新,但我一直遇到错误(下面(。
"if h2output[1] not in h1output == True or h2output[2] not in h1output == True:
IndexError: list index out of range"
doublewin = 0
h1output = []
h2output = []
h3output = []
v1output = []
v2output = []
v3output = []
d1output = []
d2output = []
for i in h1:
if i not in h1output:
h1output.append(i)
if len(h1output) == 2:
doublewin += 1
for i in h2:
if i not in h2output:
h2output.append(i)
if len(h2output) == 2:
if h2output[1] not in h1output == True or h2output[2] not in h1output == True:
doublewin += 1
作为 len(h2output)==2
,它只有2个位置,在python中以零开始,因此 h2output[2]
不超出界限,索引必须为 0
或 1
您在h2output[1]
和h2output[2]
中具有硬编码索引。他们中的任何一个都在引起问题。请检查列表的大小。
在不需要的情况下,请删除真正的布尔值。