I started learning python few days ago (with no prior programming experience nor knowledge) and am currently stuck with the following thing I do not understand: Let' say I have an unsorted list "b" and I want to sort a list "c" which looks exactly like list "b":
b = [4,3,1,2]
c=b
c.sort()
print b
print c
What I discovered is that both b and c are sorted: [1,2,3,4] [1,2,3,4]
Why is that so?
It seems this solution works perfectly when I create a copy of the "b" list:
b = [4,3,1,2]
c=b[:]
c.sort()
print b
print c
Results in: [4,3,1,2] [1,2,3,4]
But why does the first solution not work?
Thank you.