I am writing a python application where I have a variable dictionary that can be nested upto any level.
The keys in any level can be either int or string. But I want to convert all keys and values at all levels into strings. How nested the dictionary will be is variable which makes it a bit complicated.
{
"col1": {
"0": 0,
"1": 8,
"2": {
0: 2,
}
"3": 4,
"4": 5
},
"col2": {
"0": "na",
"1": 1,
"2": "na",
"3": "na",
"4": "na"
},
"col3": {
"0": 1,
"1": 3,
"2": 3,
"3": 6,
"4": 3
},
"col4": {
"0": 5,
"1": "na",
"2": "9",
"3": 9,
"4": "na"
}
}
I am looking for the shortest and quickest function to achieve that. There are other questions like Converting dictionary values in python from str to int in nested dictionary that suggest ways of doing it but none of them deals with the "variable nesting" nature of the dictionary.
Any ideas will be appreciated.