0
Help
I want to list all the keys that the dataset have using list. But i lose using recursion. Thanks for your help. https://code.sololearn.com/cp128nc2FKyF/?ref=app
2 Answers
+ 2
keys={}
def nested_object(ds):
for (k, v) in ds.items():
if(type(v) == dict):
nested_object(v)
elif(type(v) == str):
keys[k] = v
elif(type(v) == int):
keys[k] = v
elif(v is None):
keys[k] = v
else:
keys[k] = v
print (k, v, type(v))
return keys
# Keep learning & happy coding :D
+ 2
To fix the duplication of the keyname put the dot in the key
& better results will come with this code
pprint.pprint(dataset, sort_dicts=False)
I made the code better and it gives you a list and it gives you more accurate answers
https://code.sololearn.com/ctUe2ymKhrUs/#py