Understanding why this error behaves as it does
a = ['dog', 'train', 'royalty'] for x in a: if len(x) > 6: a.insert(0, "dragons") print(x) in this code I reached an endless loop and I understand that this is caused by me updating the list while the for loop is running the loop I did fix it by making a copy of a so that I would run on a elements but won't get stuck b = a[:] for x in b: if len(x) > 6: a.insert(0, "dragons") print(x) yet what leads to this question is I assumed initially that the for loop element x will begin from places zero the index will be reset and so I should have gotten dragons printed and stuck in an endless loop because of that but to my surprise I am getting royalty printed so in actuality it seems like since the loop is updated now there is an element in the last index to check but also the last element became royalty and so a keeps adding dragons to the start and royalty keeps getting printed the only things that I could come up with is that I am actually continuing from the last index to index +1 BUT SINCE I inserted an element to index 0 the previous last index is now the last I am checking and royalty is the one getting printed , so should I think of x though it is the element I have now in the list as element + index so following the logic of for i in range (Len(list)) and so i would not actually reset it would just cause the loop to continue from last index ?