I have the following nested list:
orders = [['Large', 'Latte', 2.45],
['',
'Frappes - Coffee',
2.75,
'',
'Cortado',
2.05,
'',
'Glass of milk',
0.7,
'',
'Speciality Tea - Camomile',
1.3,
'',
'Speciality Tea - Camomile',
1.3]]
Each inner list is n elements long, but always divisible by 3.
My issue is that I am trying to return a list of dictionaries by iterating through orders
with the following:
[dict(size=i[0],product=i[1],price=i[2]) for i in orders]
However, that only returns the first element inside products[1]
returns [{'size': 'Large', 'product': 'Latte', 'price': 2.45},
{'size': '', 'product': 'Frappes - Coffee', 'price': 2.75}]
I tried doing a second loop but that also doesn't work.
I want my code to output the following:
[
[{'size': 'Large', 'product': 'Latte', 'price': 2.45}],
[{'size': '', 'product': 'Frappes - Coffee', 'price': 2.75},
{'size': '', 'product': 'Cortado', 'price': 2.05},
{'size': '', 'product': 'Glass of Milk', 'price': 0.7},
{'size': '', 'product': 'Speciality Tea - Camomile', 'price': 1.3},
{'size': '', 'product': 'Speciality Tea - Camomile', 'price': 1.3}]
]
If anyone could point me in the right direction it would be much appreciated!