how to copy a dictionary in python 3.1 and edit ONLY the copy
Posted
by MadSc13ntist
on Stack Overflow
See other posts from Stack Overflow
or by MadSc13ntist
Published on 2010-03-17T21:07:06Z
Indexed on
2010/03/17
21:11 UTC
Read the original article
Hit count: 362
can someone please explain this to me??? this doesn't make any sense to me.... I copy a dictionary into another and edit the second and both are changed????
ActivePython 3.1.0.1 (ActiveState Software Inc.) based on Python 3.1 (r31:73572, Jun 28 2009, 19:55:39) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> dict1 = {"key1":"value1", "key2":"value2"} >>> dict2 = dict1 >>> dict2 {'key2': 'value2', 'key1': 'value1'} >>> dict2["key2"] = "WHY?!?!?!!?!?!?!" >>> dict1 {'key2': 'WHY?!?!?!!?!?!?!', 'key1': 'value1'} >>>
© Stack Overflow or respective owner