How do I change a python iterator mid iteration?
For example:
for i in range(10):
print i
i = 5
This prints:
0
1
...
9
I would like to print:
0
5
5
5
...
EDIT: Sorry this question came out as confusing to people. I was interested in why when I try to change an iterator during a for loop the for loop ignores it on the next iteration.
Someone else has already submitted an answer that clears my confusion. range creates a list and then the for loop assigns the iterator to the next variable in the list.
iin the loop it's not going to terminate. Even if it did - you are doing something conceptually wrong.for x in ([0] + [5]*9): print x, or even justprint '\n'.join(['0'] + ['5']*9), I don't think that's going to help with your actual problem :).