The objective here is to get a list `[1,2,3,4], and add it as is, to another list; so I can have a list of lists
masterlist = [[1,2,3,4],[5,6,7,8],.....]
But I can't get this right.
I did try append, which works, but it copy a reference to that list that I append, it does not copy the values, so if I empty the list that I did append, I end up with the whole thing being cleared.
list1 = [1,2,3,4]
masterlist.append(list1)
del list1[:]
list1 = [5,6,7,8]
masterlist.append(list1)
This result in the masterlist having 2 lists, but they are fundamentally the same, so it will look like this:
[[5,6,7,8],[5,6,7,8]]
While I want [[1,2,3,4],[5,6,7,8]]
I did try to use extend, but this add every element of the current list, as single entry in the other list, so I end up with
[1,2,3,4,5,6,7,8]
How do you end up adding in a list, the content itself of the list, and not the reference?
EDIT: This is not a question related to deep or shallow copy; the other linked question seems similar but did not solve my problem. I see a solution here that fits perfectly my case