You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As a little improvement, I slightly modified your script so that it can handle multi-level nested group.
Here is the reviewed formatKeys() function.
I am also a novice programmer, so I would not bet my life that this a 100% full proof, but I have tested it a bit on my own, and it has worked so far!
def formatKeys(data):
# pprint(data)
newDict = {"submission": {}}
for key in data:
if "remove" not in key:
newKeys = key.split("/")
currDict = newDict["submission"]
while len(newKeys)>1:
currKey = newKeys[0]
if currKey not in currDict:
newerDict = {}
currDict[currKey] = newerDict
currDict = newerDict
else:
currDict = currDict[currKey]
newKeys.pop(0)
currDict[newKeys[0]] = data[key]
return newDict
The text was updated successfully, but these errors were encountered:
Hi Palitu,
Thanks again for that work!
As a little improvement, I slightly modified your script so that it can handle multi-level nested group.
Here is the reviewed formatKeys() function.
I am also a novice programmer, so I would not bet my life that this a 100% full proof, but I have tested it a bit on my own, and it has worked so far!
def formatKeys(data):
# pprint(data)
newDict = {"submission": {}}
for key in data:
if "remove" not in key:
newKeys = key.split("/")
currDict = newDict["submission"]
while len(newKeys)>1:
currKey = newKeys[0]
if currKey not in currDict:
newerDict = {}
currDict[currKey] = newerDict
currDict = newerDict
else:
currDict = currDict[currKey]
newKeys.pop(0)
currDict[newKeys[0]] = data[key]
return newDict
The text was updated successfully, but these errors were encountered: