Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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_Arrays_List - Fatal编程技术网

Python 在循环的每次迭代中更改访问的列表

Python 在循环的每次迭代中更改访问的列表,python,arrays,list,Python,Arrays,List,如果我有密码: while d<20: num = row1[a]*row1[b]*row1[c]*row1[d] if num > largest: largest = num a+=1 b+=1 c+=1 d+=1 当d最大时: 最大=num a+=1 b+=1 c+=1 d+=1 我希望它是(在它迭代之后): 当d最大时: 最大=num a+=1 b+=1 c+=1 d+=1 我该怎么做呢。 作为参考,row

如果我有密码:

while d<20:
    num = row1[a]*row1[b]*row1[c]*row1[d]
    if num > largest:
        largest = num
    a+=1
    b+=1
    c+=1
    d+=1
当d最大时:
最大=num
a+=1
b+=1
c+=1
d+=1
我希望它是(在它迭代之后):

当d最大时:
最大=num
a+=1
b+=1
c+=1
d+=1
我该怎么做呢。 作为参考,rowx是列表,a、b、c和d是选择数据点

总而言之,我想在每次迭代后搜索一个不同的列表,这可能吗


编辑我忘了提到,重要的是每行没有不同的循环。

将列表放入一个列表中

rows = [row1, row2]  # or however many
for row in rows:
    # setup
    while d < 20:
         # your code but with row1 replaced with row
rows=[row1,row2]#或任意多
对于行中的行:
#设置
当d<20时:
#您的代码,但将行1替换为行

将列表放入列表中

rows = [row1, row2]  # or however many
for row in rows:
    # setup
    while d < 20:
         # your code but with row1 replaced with row
rows=[row1,row2]#或任意多
对于行中的行:
#设置
当d<20时:
#您的代码,但将行1替换为行

是的,可以通过迭代这些行的列表来实现

list_of_rows = [row1, row2] # etc.
for row in list_of_rows:
    while d<20:
        num = row[a]*row[b]*row[c]*row[d]
        if num > largest:
            largest = num
        a+=1
        b+=1
        c+=1
        d+=1
list_of_rows=[row1,row2]#等。
对于\u行的列表\u中的行:
虽然d最大:
最大=num
a+=1
b+=1
c+=1
d+=1

是的,可以通过迭代这些行的列表来实现

list_of_rows = [row1, row2] # etc.
for row in list_of_rows:
    while d<20:
        num = row[a]*row[b]*row[c]*row[d]
        if num > largest:
            largest = num
        a+=1
        b+=1
        c+=1
        d+=1
list_of_rows=[row1,row2]#等。
对于\u行的列表\u中的行:
虽然d最大:
最大=num
a+=1
b+=1
c+=1
d+=1

您不必假设
row3
无论rowN如何,它都可以工作,但这非常有效,谢谢@Zanolon如果您有未指定数量的
rowN
,最好将
行设置为
列表的
列表,以便于扩展。e、 g.
行=[[1,2,3,4],[1,2,3,4]…]
然后为行中的行引用
。您不必假设
row3
无论到rowN为止都有效,但这非常有效,谢谢@Zanolon如果您有未指定数量的
rowN
,最好将
行设置为
列表的
列表,以便于扩展。e、 g.
行=[[1,2,3,4],[1,2,3,4]…]
然后参考
中的行