my_list = [15, 6, 7, 8, 35, 12, 14, 4, 10, 15]
my_new_list = my_list
my_new_list.sort()
print(my_list)
print(my_new_list)
The output:
[4, 6, 7, 8, 10, 12, 14, 15, 15, 35]
[4, 6, 7, 8, 10, 12, 14, 15, 15, 35]
In this piece of code, why is my_new_list being a shallow copy of my_list? I don't understand why it isn't a deep copy. And if I wanted to have a deep copy of my_list how would I do it?
Any help would be appreciated, thank you :)