cloning though allowedit is usually prudent to avoid mutating list over which one is iterating considerfor examplethe code def removedups( )"""assumes that and are lists removes any element from that also occurs in ""for in if in remove( [ , , , [ , , , removedups( print ' =' you might be surprised to discover that the print statement produces the output [ during for loopthe implementation of python keeps track of where it is in the list using an internal counter that is incremented at the end of each iteration when the value of the counter reaches the current length of the listthe loop terminates this works as one might expect if the list is not mutated within the loopbut can have surprising consequences if the list is mutated in this casethe hidden counter starts out at discovers that [ is in and removes it--reducing the length of to the counter is then incremented to and the code proceeds to check if the value of [ is in notice that this is not the original value of [ ( )but rather the current value of [ ( as you can seeit is possible to figure out what happens when the list is modified within the loop howeverit is not easy and what happens is likely to be unintentionalas in this example one way to avoid this kind of problem is to use slicing to clone ( make copy ofthe list and write for in [:notice that writing newl followed by for in newl would not have solved the problem it would not have created copy of but would merely have introduced new name for the existing list slicing is not the only way to clone lists in python the expression list(lreturns copy of the list if the list to be copied contains mutable objects that you want to copy as wellimport the standard library module copy and use the function copy deepcopy list comprehension list comprehension provides concise way to apply an operation to the values in sequence it creates new list in which each element is the result of applying given operation to value from sequence ( the elements in another listfor examplel [ ** for in range( , )print