I have the following code:
letters = 'abcdefg'
for i in letters:
if ...
#condition that tests something I need
#once condition is satisfied, something is done, the condition is modified
# and letters becomes:
letters = letters.replace(i,'')
### Now I want to start this for loop again because my condition
### may now be met with the initial letters
How do I get my loop to start from the beginning again?
You could try an approach along these lines (tweak as needed to fit your code):
The iteration in your loop is controlled by the value of
i. As long asiis less than the length of your string (7) it will keep looping, each time incrementing the value ofi(which serves as a counter) in the loop. When you seti = 0you are (re)starting the counter again.Note that unlike with the for-loop where you had
for i in letters(andisuccessively got the value of a letter),iis a simple counter, so to access a given letter you have to index into it. I.e.,letters[i]