sweets = {
'печенье': [
{'shop': 'ашан', 'price': 10.99},
{'shop': 'пятерочка', 'price': 9.99},
{'shop': 'магнит', 'price': 11.99},
],
'конфеты': [
{'shop': 'ашан', 'price': 34.99},
{'shop': 'пятерочка', 'price': 32.99},
{'shop': 'магнит', 'price': 30.99},
],
'карамель': [
{'shop': 'ашан', 'price': 45.99},
{'shop': 'пятерочка', 'price': 46.99},
{'shop': 'магнит', 'price': 41.99},
],
'пирожное': [
{'shop': 'ашан', 'price': 67.99},
{'shop': 'пятерочка', 'price': 59.99},
{'shop': 'магнит', 'price': 62.99},
]
}
for i in sweets:
i_i = i
i_item = sweets[i]
i_qn = 0
i_pc = 0
for i in sweets[i_i]:
i_qn = i['shop']
i_pc = i['price']
if i_i == 'печенье':
min(float(i_pc)
print(max)
min_prices = dict()
for k, v in sweets.items():
min_prices[k] = dict()
for counter, i in enumerate(v):
if counter == 0:
min_prices[k]['price'] = i['price']
min_prices[k]['shop'] = i['shop']
continue
if i['price'] < min_prices[k]['price']:
min_prices[k]['price'] = i['price']
min_prices[k]['shop'] = i['shop']
pprint(min_prices)
{'карамель': {'price': 41.99, 'shop': 'магнит'},
'конфеты': {'price': 30.99, 'shop': 'магнит'},
'печенье': {'price': 9.99, 'shop': 'пятерочка'},
'пирожное': {'price': 59.99, 'shop': 'пятерочка'}}
min_prices = {k: min(v, key=lambda x: x['price']) for k, v in sweets.items()}
pprint(min_prices)
{'карамель': {'price': 41.99, 'shop': 'магнит'},
'конфеты': {'price': 30.99, 'shop': 'магнит'},
'печенье': {'price': 9.99, 'shop': 'пятерочка'},
'пирожное': {'price': 59.99, 'shop': 'пятерочка'}}
for i, item in sweets.items():
print(i, min([o['price'] for o in item]))