In this code: http://dpaste.com/1026946/ How can I avoid mutating L2 simultaneously with L1? How to separate them?
You cannot. All variables in Python are passed by reference, instead of by value.
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]]
http://dpaste.com/1027733/ http://henry.precheur.org/python/copy_list http://effbot.org/zone/python-list.htm
http://www.greenteapress.com/thinkpython/thinkCSpy/html/chap08.html http://effbot.org/pyfaq/how-do-i-copy-an-object-in-python.htm
use this instead l1=[2] l2=[l1,l1] print 'l2=',l2 l2[0]=3 print 'l2=',l2
Join our real-time social learning platform and learn together with your friends!