Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 8 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!
Latest Questions
Arriyanalol: i need help
1 day ago 7 Replies 1 Medal
Arriyanalol: CONGRATS to me
2 days ago 8 Replies 2 Medals
Legomaster346: What colleges are good that are near Arab Alabama?
1 week ago 5 Replies 0 Medals
Arriyanalol: i need help
1 week ago 6 Replies 2 Medals
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!