Добавлена функция find_most_expensive_item
This commit is contained in:
parent
40786b2517
commit
3b7d5d6f6e
13
zadanie_1.py
13
zadanie_1.py
@ -65,4 +65,15 @@ def calculate_user_total(user_orders: list[dict]) -> float:
|
||||
"""
|
||||
Суммирует все значения 'total' для одного пользователя.
|
||||
"""
|
||||
return sum(order['total'] for order in user_orders)
|
||||
return sum(order['total'] for order in user_orders)
|
||||
|
||||
|
||||
# 5. Поиск самого дорогого товара (по цене за единицу)
|
||||
def find_most_expensive_item(orders: list[dict]) -> tuple[str, float]:
|
||||
"""
|
||||
Возвращает (название, цена) товара с максимальной price.
|
||||
"""
|
||||
if not orders:
|
||||
return ('', 0.0)
|
||||
most_expensive = max(orders, key=lambda x: x['price'])
|
||||
return (most_expensive['item_name'], most_expensive['price'])
|
||||
Loading…
Reference in New Issue
Block a user