Python for loop start counter initialization

后端 未结 4 1597
后悔当初
后悔当初 2021-01-06 02:08
for iteration in range(len(list) - 1):
  index = iteration +1 #This is the line which has no effect on the inner loop
  for index in range(len(list)):
    if list[it         


        
4条回答
  •  孤城傲影
    2021-01-06 02:57

    Try this instead:

    for index in range(iteration + 1, len(l)):  # don't use "list" as a name
    

    index is being reassigned anyway within the for-loop so index = iteration + 1 is not having any effect.

提交回复
热议问题