given the following dictionary - which is dynamically so there could be any level of deepness (nested structure):
data = {
"level": {
"system": {
"text": "A Lorem ipsum colour."
},
"board": {
"core": {
"text": "Another one."
}
}
},
"peer": {
"core": {
"text": "B Lorem ipsum colour."
},
"main": {
"text": "C Lorem ipsum colour."
}
}
}
The goal is to extract the text
elements orderd (from top to bottom), the result should be something like:
result = "A Lorem ipsum colour. Another one. B Lorem ipsum colour. C Lorem ipsum colour.
I think I've to use some type of recursion but I can't get it. What I get so far - and what is not working - is the following:
for k, v in data.items():
if isinstance(v, dict):
# i think i have to continue here on a deeper recursion level
else:
return v["text"]
Best regards