Sorry for the inconvinience. I realised that the example is correct. Thanks & Regards Abhinav Tyagi On 12 April 2015 at 18:38, Abhinav Tyagi <abhityagi85@gmail.com> 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']
Should be something like this (but still leaves duplicate elements in the list): ----------------------------------- words_tmp = copy.deepcopy(words) for w in words_tmp: if len(w)>6 : words.insert(0,w) -----------------------------------
Thanks & Regards Abhinav Tyagi