Learning Python: using list to make copy

About

Using list make a copy without changing original copy.



Code

a = [5, 3, 1, -1, -3, 5]
a1 = [5, 3, 1, -1, -3, 5]

b = a
b[0]=0

#This is how to make a copy of a list without changing the 
#original copy of it
b1=list(a1)
b1[0]

print "This is changing the original copy as well"
print "Original a copy: ", a
print "This is b:", b


print "This doesn't change the original copy but made a new copy instead"
print "Original coyp of: ", a1
print "This is b1 copy: ", b1




Output

This is changing the original copy as well
Original a copy:  [0, 3, 1, -1, -3, 5]
This is b: [0, 3, 1, -1, -3, 5]
This doesn't change the original copy but made a new copy instead
Original coyp of:  [5, 3, 1, -1, -3, 5]
This is b1 copy:  [5, 3, 1, -1, -3, 5]



Explanation
The assignment b = list(a) created a copy of the list a. Setting b[0] = 0 only mutated the copy of the list, not the original list.  As a result, a[0] == 5.