I want to:
create a copy of a global list that already exists,
modify the contents of this new list without affecting the original one,
print both lists
all inside a function.
My code:
original_list = ['tom', 'adam', 'john']
def a():
new_list = original_list
new_list[1] = 'simon'
print(original_list, new_list)
a()
Expected result:
['tom', 'adam', 'john'] ['tom', 'simon', 'john']
Actual result:
['tom', 'simon', 'john'] ['tom', 'simon', 'john']
Please explain why my code behaves the way it does and not as I expect it to.
Thanks in advance!