1
a = [1, 2, 4, 5, 7, 8, 10]
n = len(a)
d = 3
c = []
for i in range(n):
  for j in range(i,n):
    for k in range(j,n):
        for x,y,z in zip(a[i],a[j],a[k]):
            print(x,y,z)

Error : Traceback (most recent call last):
File "", line 8, in TypeError: 'int' object is not iterable

It works when I convert list object to string but not working in int.

ThePyGuy
  • 17,779
  • 5
  • 18
  • 45
Prime coder
  • 91
  • 1
  • 10

1 Answers1

3

Because indexing will give back the object and not an iterable container here. unless you call it like this: zip([a[i]], [a[j]], [a[k]]).

a = [1, 2, 4, 5, 7, 8, 10]
n = len(a)
d = 3
c = []
for i in range(n):
  for j in range(i,n):
    for k in range(j,n):
        for x,y,z in zip([a[i]], [a[j]], [a[k]]):
            print(x,y,z)
Anurag Dhadse
  • 1,722
  • 1
  • 13
  • 26