python objects confusion

Posted by james on Stack Overflow See other posts from Stack Overflow or by james
Published on 2011-01-03T20:31:12Z Indexed on 2011/01/03 20:54 UTC
Read the original article Hit count: 170

Filed under:
|

wow i thought i knew python untill tonight.. what is the correct way to do something like this.. heres my code

a = ["one", "two", "three"]
b = a  #here i want a complete copy that when b is changed, has absolutely no effect on a
b.append["four"]
print a  #a now has "four" in it..

so basically i want to know, instead of the b = a step, how would i correctly make a copy of a list or dictionary so that when b is changed a does not change along with it.. thanks guys

© Stack Overflow or respective owner

Related posts about python

Related posts about variables