TypeError: 'itertools.combinations' object is not indexable

When I try to run:

temp = (twoset2[x][i][0]-twoset[x][i][1])

I get:

TypeError: 'itertools.combinations' object cannot be decrypted

My code is:

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

Basically what I'm trying to do is: I have a list ( twoset2) of 2 elements of a subset of coordinates (example:) ((2,0) (3,3). I want to access each individual coordinate, and then take the difference between xand yand put it in DSET, but when I try to run this error, I get.

Please, help!

+4
source share
2 answers

itertools.combinations , . , , , .

:

import itertools
for combination in itertools.combinations([1,2,3], 2):
    print combination

:

(1, 2)
(1, 3)
(2, 3)
+4

twoset2 ; itertools.combinations ( ):

>>> import itertools
>>> itertools.combinations([1, 2, 3], 2)
<itertools.combinations object at 0x01ACDC30>
>>>
>>> twoset2 = itertools.combinations([1, 2, 3], 2)
>>> twoset2[0]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'itertools.combinations' object is not subscriptable
>>>

, :

twoset2 = list(itertools.combinations(...))
+1

All Articles