I'm trying build a nested dictionary from a jagged excel file (image here:
), which I'm trying to add more 'children' to:
dict = {'levelA': {'levelA1': 'levelA11', 'LevelA2': 'LevelA21'},
'levelB': {'levelB1': 'levelB11'},
'levelC': {'levelC1': 'levelC12'}}
I want to find the value of:
"levelA21"
and replace it with a dictionary of the form:
['levelA21']['levelA211'] = "value"
I tried:
dict = {'levelA1': ["value1", "value"],
"LevelB1": ["value77", "something"] }
(wrong), and
"value" in [x for v in dict.values() for x in v]
which is true.
My code deals with the merged xls cells and removed NoneType from empty cells.
So after finding the dict.value() instance of "levelA21", can I replace it with a another nested level with key = "level21", item = "levelA211", and value = "value"?
Also, I'm removing the used keys and items, (first two columns), iteratively.
I think I should be building this recursively from right to left from the deepest (right-most) level and merging as I go, but I cannot grasp it.
Happy to share code class in entirety; it's documented pretty well.