当我尝试运行时:
temp = (twoset2[x][i][0]-twoset[x][i][1])
I get:
类型错误:“itertools.combinations”对象不可下标
My code:
for x in range(0,64):
for i in range(0,1):
temp = (twoset2[x][i][0]-twoset[x][i][1])
DSET[counter2]= temp
temp = 0
counter2 += 1
基本上我想做的是:我有一个清单(twoset2
)的坐标的 2 个元素子集(例如:((2,0) (3,3)
)。我想访问每个单独的坐标,然后获取两者之间的差异x
and y
并将其放入DSET
,但是在尝试运行时出现上述错误。
请帮忙!
itertools.combinations https://docs.python.org/2/library/itertools.html#itertools.combinations返回一个生成器而不是一个列表。这意味着您可以对其进行迭代,但不能像您尝试的那样使用索引逐个元素地访问它。
相反,您可以像这样获得每个组合:
import itertools
for combination in itertools.combinations([1,2,3], 2):
print combination
这给出:
(1, 2)
(1, 3)
(2, 3)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)