Academic Work Personal
|
Python /
Deep copy of a list
a = [1,2,3] # [1,2,3] b = a # just a reference to list 'a' b.append(10) # 10 is appended to both 'a' and 'b' print a # [1,2,3,10] print "==========" from copy import copy a = [1,2,3] # [1,2,3] b = copy(a) # deep copy, 'b' is a new list: [1,2,3] a.append(4) # 'a' is now [1,2,3,4] print b # 'b' is still [1,2,3] print "==========" a = [1,2,3] # [1,2,3] b = a[:] # 'b' is a NEW list, a copy of 'a' b.append(10) # 10 is appended to 'b' only print a # [1,2,3] |
anime | bash | blogs | bsd | c/c++ | c64 | calc | comics | convert | cube | del.icio.us | digg | east | eBooks | egeszseg | elite | firefox | flash | fun | games | gimp | google | groovy | hardware | hit&run | howto | java | javascript | knife | lang | latex | liferay | linux | lovecraft | magyar | maths | movies | music | p2p | perl | pdf | photoshop | php | pmwiki | prog | python | radio | recept | rts | scala | scene | sci-fi | scripting | security | shell | space | súlyos | telephone | torrente | translate | ubuntu | vim | wallpapers | webutils | wikis | windows Blogs and Dev. * Ubuntu Incident Places Debrecen | France | Hungary | Montreal | Nancy Notes Hobby Projects * Jabba's Codes Quick Links [ edit ] |