Python acting weird

W

Westly Ward

x = {"type":"folder", "name":"sonicbot", "data":[{"type":"folder",
"name":"SonicMail", "data":[{"type":"file", "name":"bbcode.py",
"compressed":False, "contents":"blahblahfilecontents"}]}]}
print x
def setindict(dictionary, keys, value) :
if len(keys) == 1 :
if keys[0].isdigit() and int(keys[0]) == len(dictionary) :
dictionary.append(keys[0])
else :
dictionary[keys[0]] = value
else :
dictionary[keys[0]] = setindict(dictionary[keys[0]], keys[1:], value)
return dictionary
a = x.copy()

print id(a), id(x)
y = setindict(a, ["data", 0, "data", 0, "compressed"], True)
if y == x :
print True

else :
print False
print x
print a

How are x and a are ending up the same? I would think .copy() would
make it completely seperate.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top