I read here and have learned through bad code that there are problems iterating over lists and changing the list elements within the loop. They suggest one method is to create a copy of the list as such:
for x in a[:]: # make a slice copy of the entire list
if len(x) > 6: a.insert(0, x)
Does referring to a slice of a list create a temporary copy created for execution of the loop?
What about in the following case found here:
somelist[:] = [x for x in somelist if not determine(x)]
In this case instead of assigning the solution to a new list, they assign output to a slice of the input list. What is the order of operations here which allows this to be done? Why do we not run into the same errors mentioned when modifying list elements through usual for loops?