Is there a way to return a list of all dictionary keys in the provided input (at all levels)?
The keys should be ordered by level, for example:
{
"A": 1,
"B": [{
"B1": 1,
"B2": 1
}, {
"B3": 1,
"B4": 1
}],
"C": {
"C1": 1,
"C2": 1
}
}
I have tried using dict.keys()
and dict.items()
but did not get the desired output.
The output should be like this ["A", "B", "C", "B1", "B2", "B3", "B4", "C1", "C2"]
.
Any help is appreciated.