I am generating triples of numbers and trying to put them in a list which I will later process. In the code below Iām adding a triple Elt to a list L with one triple. How can I keep future changes to Elt from modifying L? Should be super easy, but how?
L = [[2, 3, 4]]
Elt = [5, 6, 7]
def proc1(BigList, NewElt):
BigList = BigList + [NewElt.copy()]
return(BigList)
print(L)
L = proc1(L, Elt)
print(L)
Elt[1] = 70 # now L[1] is different from Elt
print(L)
print(Elt)
Output:
[[2, 3, 4]]
[[2, 3, 4], [5, 6, 7]]
[[2, 3, 4], [5, 6, 7]]
[5, 70, 7]
EDIT: In fact, I was looking for call-by-value. Now I understand. Thanks!