{
'Key1':{ 'price': 40,
'amount': 30
},
'Key2':{ 'price': 50,
'amount': 40
},
'Key3':{ 'price': 70,
'amount': 50
}
}
How to get all the prices?
{
'Key1':{ 'price': 40,
'amount': 30
},
'Key2':{ 'price': 50,
'amount': 40
},
'Key3':{ 'price': 70,
'amount': 50
}
}
How to get all the prices?
Here is one way to do it:
d={
'Key1':{ 'price': 40,
'amount': 30
},
'Key2':{ 'price': 50,
'amount': 40
},
'Key3':{ 'price': 70,
'amount': 50
}
}
prices=[k['price'] for i,k in d.items()]
print(prices)
Output:
[40, 50, 70]