-
www说
用于*nestedList解压参数列表值,然后zip迭代它们:nestedList = [[1,2,3],[4,5,6]]for a in zip(*nestedList): print(a)输出:(1, 4)(2, 5)(3, 6)
-
繁星淼淼
使用简单的 for 循环和“”.join() 将嵌套列表中的每个 int 映射到带有 map() 的 str。例子:>>> ys = [[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]>>> for xs in ys:... print(" ".join(map(str, xs)))... 1 2 34 5 67 8 9 10
-
元芳怎么了
您可以在 for 循环中使用 zip() ,输出应如下所示:(1,4)(2,5)(3,6)或使用这样的简单代码:nestedList = [[1,2,3],[4,5,6]]l1 = nestedList[0]l2 = nestedList[1]for i in range(3): print(l1[i],' ',l2[i])输出应该是这样的:1 42 53 6
-
牛魔王的故事
您可以简单地使用嵌套的 for 循环来按预期打印:nestedlist = [[1,2,3],[4,5,6]]for i in range(len(nestedlist)-1): for j in range(len(nestedlist[i])): print(nl[i][j]," ",nl[i+1][j])输出:1 42 53 6