I wanted to reverse a list, and I managed to do so, but in the middle of the work I noticed something strange. The following program works as expected but uncommeting line <
This is about general behaviour of lists in python. Doing:
list_reversed = list
doesn't copy the list, but a reference to it. You can run:
print(id(list_reversed))
print(id(list))
Both would output the same, meaning they are the same object. You can copy lists by:
a = [1,2]
b = a.copy()
or
a = [1,2]
b = a[:]