One of the valid ways to solve this problem is by performing a deep copy of list one.
This process can be obtained using the method deepcopy library copy
OBSERVING:
A deep copy builds a new composite object and then recursively inserts copies of the objects found in the original.
This way we can implement the following code:
from copy import deepcopy
listaUm = [1, 2, 3, 4]
listaDois = deepcopy(listaUm)
listaDois.remove(3)
print(listaUm)
print(listaDois)
Note that this code initially defines listDois as a deep copy of list one. Thus, listDois is a faithful copy of list one only at another memory address.
Then, from this moment we may remove any value from listDois without interfering with list one.
Executing said code, we obtain as output:
[1, 2, 3, 4]
[1, 2, 4]
Thank you very much, solved my problem!
– Rafael Cabral
an easier way is
listaDois = list(listaUm)
– drgarcia1986
Why does this happen? What is this reference that is being copied? It could develop this part better?
– yoyo