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-Apr-2015 6:48 pm, "Tim Golden" <mail@timgolden.me.uk> wrote:
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

for  w  in  words[:]:   # Loop over a slice copy of the entire list.
...     if  len(w)  >  6:
...         words.insert(0,  w)
...
words
['defenestrate', 'cat', 'window', 'defenestrate']

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