I have this list here:
mechs= [
{
'type_code': 'GAT',
'name': 'STRIKE',
'unit_price': 3500,
'minimum_kilo': 500,
},
{
'type_code': 'GAT',
'name': 'BLITZ',
'unit_price': 2500,
'minimum_kilo': 520,
},
{
'type_code': 'ZGMF',
'name': 'LEGEND',
'unit_price': 4500,
'minimum_kilo': 550,
},
]
Then I wanted the output to be like:
mechas=
{'GAT': {
[
{'type_code': 'GAT',
'name': 'STRIKE',
'unit_price': 3500,
'minimum_kilo': 500},
{'type_code': 'GAT',
'name': 'BLITZ',
'unit_price': 2500,
'minimum_kilo': 520}
]
}
#continue to next dict...
How do I get the 'GAT' dict to put the next value(dict) to the dict instead of reassigning them?
Here is what I have used:
mechas={}
for i in mechs:
mechas[i['type_code']]=i
And the output is like this:
{'GAT': {'type_code': 'GAT',
'name': 'BLITZ',
'unit_price': 2500,
'minimum_kilo': 520},
'ZGMF': {'type_code': 'ZGMF',
'name': 'LEGEND',
'unit_price': 4500,
'minimum_kilo': 550}}
This output does not include the previous value (code GAT name STRIKE), so how do I keep it instead of reassigning a new value?
I actually tried list(), append(), etc. but I think it's too long to put it here and the result still does not satisfy me.