Python代码循环遍历一个每个周期有2个变量的列表

Python代码循环遍历一个每个周期有2个变量的列表,python,list,loops,Python,List,Loops,我试图理解如何添加一个2变量列表,并让python代码像循环一样循环 比如说 [1,9],[2,9],[3,7],[4.6],[5,9],[6,9]] 在下面的示例中 12,9,其中12将用于填充M,它将在代码中迭代9次,使length=9,然后在完成后继续下一次迭代2,9,等等 #This is how many iterations are needed list = [1,2,3,4,5,6,7,8,9] # Getting length of list length =

我试图理解如何添加一个2变量列表,并让python代码像循环一样循环

比如说

[1,9],[2,9],[3,7],[4.6],[5,9],[6,9]]

在下面的示例中 12,9,其中12将用于填充M,它将在代码中迭代9次,使length=9,然后在完成后继续下一次迭代2,9,等等

#This is how many iterations are needed
  list = [1,2,3,4,5,6,7,8,9]


# Getting length of list 
   length = len(list) 
   i = 0

   # Iterating using while loop 
     while i < length: 

   #This is the ID    
     m = '12'

我想你是想做这样的事情:

mylist = [[1, 9], [2, 9], [3, 7], [4, 6], [5, 9], [6, 9]]

for first, second in mylist:
    M = first
    for i in range(second):
        print(f'The ID is {M}, iteration number {i}')

你能澄清一下你的意思吗,并删除代码中无用的部分吗?如果你能提供预期的结果,那会有帮助的。。我只是想了解我能不能输入一个基于两个变量的列表和循环。。。目前,它是在列表长度的1上进行的,但每个项目都有一个列表长度和一个附加值。。。所以基本上是一对价值观…我愿意帮忙,我相信我能找到解决办法。然而,我无法理解你的问题,由于没有答案,我无法告诉其他人是否理解。我建议你包括你的预期输出,并适当地设置你的列表格式,例如,[[1,9],[2,9]]干杯,尼古拉斯,我认为这很有帮助,我不知道这是如何形成列表的奇妙的尼古拉斯,工作得很好,非常感谢你抽出时间来帮助,非常有价值的部分是列表,以及如何为这两个值构建列表。非常感谢你的朋友。
The ID is 1, iteration number 0
The ID is 1, iteration number 1
The ID is 1, iteration number 2
The ID is 1, iteration number 3
The ID is 1, iteration number 4
The ID is 1, iteration number 5
The ID is 1, iteration number 6
The ID is 1, iteration number 7
The ID is 1, iteration number 8
The ID is 2, iteration number 0
The ID is 2, iteration number 1
The ID is 2, iteration number 2
The ID is 2, iteration number 3
...