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.
"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.