I am trying to modify a list and since my modifications were getting a bit tricky and my list large I took a slice of my list using the following code
tempList=origList[0:10]
for item in tempList:
item[-1].insert(0 , item[1])
del item[1]
I did this thinking that all of the modifications to the list would affect tempList object and not origList objects.
Well once I got my code right and ran it on my original list the first ten items (indexed 0-9) were affected by my manipulation in testing the code printed above.
So I googled it and I find references that say taking a slice copies the list and creates a new-one. I also found code that helped me find the id of the items so I created my origList from scratch, got the ids of the first ten items. I sliced the list again and found that the ids from the slices matched the ids from the first ten items of the origList.
I found more notes that suggested a more pythonic way to copy a list would be to use
tempList=list(origList([0:10])
I tried that and I still find that the ids from the tempList match the ids from the origList.
Please don't suggest better ways to do the coding-I am going to figure out how to do this in a list Comprehension on my own after I understand what how copying works
Based on Kai's answer the correct method is:
import copy
tempList=copy.deepcopy(origList[0:10])
id(origList[0])
>>>>42980096
id(tempList[0])
>>>>42714136
Works like a charm