I have a nested dictionary which contains the data about books:
- UID
- Condition
- Price
Here is the definition:
books = {
'uid1':
{'price': '100',
'condition': 'good'},
'uid2':
{'price': '80',
'condition': 'fair'},
'uid3':
{'price': '150',
'condition': 'excellent'},
'uid4':
{'price': '70',
'condition': 'fair'},
'uid5':
{'price': '180',
'condition': 'excellent'},
'uid6':
{'price': '60',
'condition': 'fair'}
}
I need to get average prices, grouped by condition. So, the intended result is:
{'fair': 70, 'good': 100, 'excellent': 165}
What is the most Pythonic way to do it?