Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- L1 = [2] # Creates object 2(type int) and put it in L1(list) at [0] index
- L2 = [L1, L1] # Put reference links in L2(list) to L1(list) at [0] index and [1] index]
- print 'L2 =', L2 # Prints L2(list)
- L1[0] = 3 # Creates object 3(type int) and re-assign [0] index in L1(list) to it
- print 'L2 =', L2 # Prints L2(list)
- ##
- # L2(list) changing because it contain 2 reference links to L1(list) not values
- # one refernce at [0] index another one at [1] index
- # to avoid mutating u should assign value of L1 to L2 at index's [0] and [1]
- # L2 = [L1[0], L1[0]]
- ##
Advertisement
Add Comment
Please, Sign In to add comment