'int' 在 python 中使用 zip 时对象不可迭代

'int' object is not iterable while using zip in python

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

当我将列表对象转换为字符串但在 int 中不起作用时它起作用。

因为索引会返回对象而不是这里的可迭代容器。除非你这样称呼它: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)