/
Cosm03
/
cook_book
Обзор
Документация
Войти
/
Cosm03
/
cook_book
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
task1.py
32 строки
875 B
Cosm03
task1
21 май 2026, 14:31
21 май 2026, 14:31
5eb0ecd
Код
Авторство
О чём код?
def parse_recipes(file_path): cook_book = {} with open(file_path, encoding="utf-8") as file: lines = [line.strip() for line in file if line.strip()] i = 0 while i < len(lines): dish_name = lines[i] ingredients_count = int(lines[i + 1]) ingredients = [] for j in range(ingredients_count): ingredient_name, quantity, measure = [ part.strip() for part in lines[i + 2 + j].split("|") ] ingredients.append( { "ingredient_name": ingredient_name, "quantity": int(quantity), "measure": measure, } ) cook_book[dish_name] = ingredients i += ingredients_count + 2 return cook_book if __name__ == "__main__": print(parse_recipes("recipes.txt"))