my .pop() function affects multiple lists, do i need to store the first list in another way?

Viewed 30

I try to save a new list with the variables of an old list, and then .pop() the last item from the new list without affecting the old list.

new = ['Bram', 'Glenn', 'Menno']
old = ['Glenn', 'Menno', 'Eefke Maria']

print('new1', new)
print('old1', old)
new = old
print('new2', new)
print('old2', old)
new.pop()
print('new3', new)
print('old3', old)

this gives the output:

new1 ['Bram', 'Glenn', 'Menno']
old1 ['Glenn', 'Menno', 'Eefke Maria']
new2 ['Glenn', 'Menno', 'Eefke Maria']
old2 ['Glenn', 'Menno', 'Eefke Maria']
new3 ['Glenn', 'Menno']
old3 ['Glenn', 'Menno']

But I would like the output:

new1 ['Bram', 'Glenn', 'Menno']
old1 ['Glenn', 'Menno', 'Eefke Maria']
new2 ['Glenn', 'Menno', 'Eefke Maria']
old2 ['Glenn', 'Menno', 'Eefke Maria']
new3 ['Glenn', 'Menno']
old3 ['Glenn', 'Menno', 'Eefke Maria']

Is it the way I store my list variables?

1 Answers
Related