I'm pretty new to python and would like to ask for your help or idea in converting nested list to dictionary.
Here is a sample data:
l3 = [['A', 'A-1', 'A-1-1'],
['A', 'A-1', 'A-1-2'],
['A', 'B-1', 'B-1-1'],
['A', 'B-2', nan]]
the expected output is like this:
output = {
'prod': 'A',
'item': [
{
'prod': 'A-1',
'item': [
{
'prod': 'A-1-1'
'item': []
},
{
'prod': 'A-1-2'
'item': []
}
]
},
{
'prod': 'B-1',
'item': [
{
'prod': 'B-1-1'
'item': []
}
]
},
{
'prod': 'B-2',
'item': []
}
]
}
I've tried following this link but I am having difficulty to implement it. Python: Combine several nested lists into a dictionary
Is there a way to do this? Thank you in advance for helping me.