Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 12 Online
OpenStudy (wolter1980):

In this code: http://dpaste.com/1026946/ How can I avoid mutating L2 simultaneously with L1? How to separate them?

OpenStudy (tyteen4a03):

You cannot. All variables in Python are passed by reference, instead of by value.

OpenStudy (anonymous):

http://pastebin.com/Cz1ta0Wm 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]]

OpenStudy (anonymous):

http://python.net/~mwh/hacks/objectthink.html

OpenStudy (anonymous):

use this instead l1=[2] l2=[l1,l1] print 'l2=',l2 l2[0]=3 print 'l2=',l2

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!