如何在python中迭代两个列表并按索引顺序重复较小的列表?

如何在python中迭代两个列表并按索引顺序重复较小的列表?,python,list,Python,List,我试图遍历列表“网格”,这样我就可以得到一个模式,当它到达“网格”列表中的最后一个列表时,按照索引重复自身的顺序打印每个列表,直到它与pri_分数中的数字相同 在终端中运行时,我没有收到任何错误消息 编辑: 我已经开始工作了,这就是我所做的 pri_score = input("What did you score? ") print mark(pri_score) ite = 0 grid = [['0','0','1','0','0'], ['0','1','1','1','0'], ['

我试图遍历列表“网格”,这样我就可以得到一个模式,当它到达“网格”列表中的最后一个列表时,按照索引重复自身的顺序打印每个列表,直到它与pri_分数中的数字相同

在终端中运行时,我没有收到任何错误消息

编辑: 我已经开始工作了,这就是我所做的

pri_score = input("What did you score? ")
print mark(pri_score)
ite = 0

grid = [['0','0','1','0','0'],
['0','1','1','1','0'],
['1','1','1','1','1'],
['0','1','1','1','0'],
['0','0','1','0','0'],
['0','0','0','0','0']]

grid_index = 0

while ite < pri_score:
    if grid_index == 5:
        grid_index = 0
    else:
        grid_index += 1
        print grid[grid_index]
    ite += 1
pri_score=input(“你的分数是多少?”)
打印分数(pri_分数)
ite=0
网格=[[0'、'0'、'1'、'0'、'0'],
['0','1','1','1','0'],
['1','1','1','1','1'],
['0','1','1','1','0'],
['0','0','1','0','0'],
['0','0','0','0','0']]
网格索引=0
当ite
我认为应该是:

while ite < pri_score:     # less than instead of greater than
而ite
试试这个,它可能会让你的生活更轻松:

pri_score = input("What did you score? ")
print mark(pri_score)

grid = [['0','0','1','0','0'],
['0','1','1','1','0'],
['1','1','1','1','1'],
['0','1','1','1','0'],
['0','0','1','0','0'],
['0','0','0','0','0']]

for i in range(pri_score):
    print grid[ i % len(grid) ]

您想要的重复模式的基本技巧是模运算符%,避免手动迭代器变量是python中的一个标准习惯用法。

pri_分数是负数吗?谢谢,但我现在已经做了,我现在将重新发布工作版本。