/
yozer
/
RecipesFiles
Обзор
Документация
Войти
/
yozer
/
RecipesFiles
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
cooking.py
28 строк
969 B
Kit os
initial
15 май 2025, 16:04
15 май 2025, 16:04
860ea3a
Код
Авторство
О чём код?
with open("recipes.txt", encoding='UTF-8') as r: c = r.read().split(sep='\n\n') cook_list = [] for i in c: cook_list.append(i.split(sep='\n')) # print(cook_list,'\n') cook_book = {} for i in cook_list: cook_book[i[0]] = [] for a in i[2: ]: d = a.split(sep='|') v = {'ingredient_name' : d[0], 'quantity' : d[1], 'measure' : d[2]} cook_book[i[0]].append(v) print(cook_book,'\n') def get_shop_list_by_dishes(dishes, person_count): shop_list = {} for d in dishes: for i in cook_book[d]: if i['ingredient_name'] in shop_list: shop_list[i['ingredient_name']]['quantity'] += int(i['quantity']) * person_count else: t = {'measure' : i['measure'], 'quantity' : int(i['quantity']) * person_count} shop_list[i['ingredient_name']] = t return shop_list print(get_shop_list_by_dishes(['Запеченный картофель', 'Омлет'], 2))