I want to do the following query:
I am creating a dictionary from data that comes from a CSV. I have a key that has different values, so I added this line of code looking if that ID previously exists in the dictionary, add those values to that key. If it doesn't exist, create the values.
if item_id in item_data:
item_data [item_id] + = [subtitle_id, subtitle_name, original_amount, amount_to_march, currency]
else:
item_data [item_id] = [subtitle_id, subtitle_name, original_amount, amount_to_march, currency]
The problem is that the output generated is something like this:
{'01': ['08',
'OTHER CURRENT INCOME',
311948.0,
311948.0,
'CLP',
'09',
'TAX CONTRIBUTION',
18414647.0,
18536395.0,
'CLP',
'10',
'SALE OF NON-FINANCIAL ASSETS',
16929.0,
16929.0,
'CLP',
'15',
'INITIAL CASH BALANCE',
1000.0,
842590.0,
'CLP',
'21',
'PERSONNEL EXPENSES',
8189139.0,
8189139.0,
'CLP']
And what I need is something like this:
{'01': {'subtitle_id':'08',
'subtitle_name':'OTHER CURRENT INCOME',
'original_amount':311948.0,
'amount_to_march':311948.0,
'currency': 'CLP'},
{'subtitle_id':'09',
'subtitle_name':'TAX CONTRIBUTION',
'original_amount':18414647.0,
'amount_to_march':18536395.0,
'currency':'CLP'},
{'subtitle_id':'10',
'subtitle_name':'SALE OF NON-FINANCIAL ASSETS',
'original_amount':16929.0,
'amount_to_march':16929.0,
'currency':'CLP'},
{'subtitle_id':'15',
'subtitle_name':'INITIAL CASH BALANCE',
'original_amount':1000.0,
'amount_to_march':842590.0,
'currency':'CLP'},
{'subtitle_id':'21',
'subtitle_name':'PERSONNEL EXPENSES',
'original_amount':8189139.0,
'amount_to_march':8189139.0,
'currency':'CLP'}
How could I create such a nested dictionary, so to speak?
Thanks a lot!