Help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

27th Oct 2021, 8:50 PM
Emanuel Maliaño
Emanuel Maliaño - avatar
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
31st Oct 2021, 4:28 PM
SoloProg
SoloProg - avatar
+ 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
1st Nov 2021, 11:51 AM
SoloProg
SoloProg - avatar