Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 循环结构,嵌套列表。_Python_Loops_Indexing - Fatal编程技术网

Python 循环结构,嵌套列表。

Python 循环结构,嵌套列表。,python,loops,indexing,Python,Loops,Indexing,这是一个简单的测试函数,与我的实际代码同义。 所以我有一组这样的数据结构 a=[[1,2,3,4,5],[0,3,6,8,10],[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]] 我试图循环它,以便在每次传递中,我们得到第一个列表的第一个元素,第二个列表的第一个元素,然后第三个列表的第一个列表的每个元素 像这样 for i,j in enumerate(a): print 'iterations',i print a[0][

这是一个简单的测试函数,与我的实际代码同义。 所以我有一组这样的数据结构

a=[[1,2,3,4,5],[0,3,6,8,10],[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]

我试图循环它,以便在每次传递中,我们得到第一个列表的第一个元素,第二个列表的第一个元素,然后第三个列表的第一个列表的每个元素

像这样

for i,j in enumerate(a):
     print 'iterations',i
     print a[0][i]
     print a[1][i]
     print a[2][i][0]
     print a[2][i][1]
     print a[2][i][2]
     print a[2][i][3]
但由于某些原因,我不能通过I=2。有人能解释一下我为什么以及如何纠正这一点吗。
谢谢没有错误,它只在i=2处结束

仔细查看数据结构:

a = [
        [1,2,3,4,5],
        [0,3,6,8,10],
        [ 
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4]
        ]
    ]

显然,
a
中只有3个元素,因此2是最后一个索引…

仔细查看数据结构:

a = [
        [1,2,3,4,5],
        [0,3,6,8,10],
        [ 
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4]
        ]
    ]

显然,
a
中只有3个元素,因此2是最后一个索引…

仔细查看数据结构:

a = [
        [1,2,3,4,5],
        [0,3,6,8,10],
        [ 
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4]
        ]
    ]

显然,
a
中只有3个元素,因此2是最后一个索引…

仔细查看数据结构:

a = [
        [1,2,3,4,5],
        [0,3,6,8,10],
        [ 
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4],
            [1,2,3,4]
        ]
    ]

显然,在
a
中只有3个元素,因此2是最后一个索引…

是的,它以2结尾,因为在第一级有三个列表简单:
len(a)==3。是的,它以2结尾,因为在第一级有三个列表简单:
len(a)==3
在您的示例中。是的,它以2结尾,因为您在第一级有三个列表简单:
len(a)==3
在您的示例中。是的,它以2结尾,因为您在第一级有三个列表简单:
len(a)==3
在您的示例中。请注意,
pprint.pprint
可用于发现此类错误。请注意,
pprint.pprint
可用于发现此类错误。请注意,
pprint.pprint
可用于发现此类错误。