I am having an issue with calling a for loop if it's range is increasing.
I have a table (list of lists):
for i in range(0, len(table)):
if len(table[i]) > 10:
new_row = table[i][11:]
table.insert(i+1, [])
for val in new_row:
table[i+1].append(val)
e.g The length of table was 50 and there are a number of rows where I have more than 10 values. After every new row is created (table.insert(i+1, []), the length of the table increases, so by the time the loop gets to row 49 where the row list is greater than 10, it's actual row number becomes greater than the range of the loop.
How can I make the loop know that the range increases? At the moment, only rows upto 50 have if condition applied
I tried adding a count variable before the loop:
count = 0
for i in range(0, len(table)+count):
if len(table[i]) > 10:
new_row = table[i][11:]
table.insert(i+1, [])
for val in new_row:
table[i+1].append(val)
count = count + 1
This did not seem to help! Maybe some sort of recursive function within the for loop to constantly poll the table length? I'm not too sure.
Thanks