I have a list
arr = [1, 2, 3, 4, 5]
I create a different list that should have the same values as arr
by assigning arr
to arr2
:
arr2 = arr
I assumed that arr
and arr1
are different variables.
But when I perform a pop
action on either one of those lists, the other list gets affected too.
What is the best way to approach this problem if I don't want to hard code values into a variable that should have the values of an already existing variable?
>>> arr = [1, 2, 3, 4, 5]
>>> arr1 = arr
>>> arr.pop(0)
>>> print(arr)
[2, 3, 4, 5]
>>> print(arr1)
[2, 3, 4, 5]