Just after I wrote the email, I realised I made a mistake and within few minutes I replied to my email that example was fine.
On 12/04/2015 14:08, Abhinav Tyagi wrote:
Following example in Section 4.2 would run into infinite loop.
https://docs.python.org/2/tutorial/controlflow.html#for-statements
... if len(w) > 6:for w in words[:]: # Loop over a slice copy of the entire list.
... words.insert(0, w)
...
['defenestrate', 'cat', 'window', 'defenestrate']words
Except that it doesn't. You seem to have missed the entire point of that particular example, which is that [:] makes a copy of the list, so mutating the original list will not affect the loop.
Did you actually try it in an interpreter?
TJG