Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-level group handling #1

Open
mcarriere1256 opened this issue Jul 29, 2024 · 0 comments
Open

Multi-level group handling #1

mcarriere1256 opened this issue Jul 29, 2024 · 0 comments

Comments

@mcarriere1256
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant