If I have the following list:
iterations = [10, 20, 30, 40, 50, 60]
And I want to write a for loop where the first item in the list is the number of iterations my for loop goes through, how would I be able to do that? Is it even possible?
I have tried it with:
for i in range(len(iteration)):
but this takes the length of the list, which is 6. I want the for loop to go through 10 iterations first, then 20 then 30 and so on. I also tried to index the first item in the list, but I don’t think it is the correct syntax.
for i in range(len(iteration)): iteration = iterations[i]
I’m new to python and I would really appreciate the help.
Looking though your comments it seems that you have a weird mixup somewhere.
If you have floats as entries in your
iterations list, you have to convert them to ints, as you cannot do, e.g. 30% of an iteration, you always have to do 100% of the instructions inside the loop. To convert floats to ints you can round down/up closest, etc.
iterations = [10.2,10.7,20,50] for it_count in iterations: for _ in range(int(it_count)): doStuff()
This example always rounds down.