/
chokehold
/
HomeWork_Open_Read_File
Обзор
Документация
Войти
/
chokehold
/
HomeWork_Open_Read_File
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
HW1.py
34 строки
980 B
chokehold
HW_1_2_rework
25 май 2026, 16:29
Верифицирован
25 май 2026, 16:29
924f32f
Код
Авторство
О чём код?
def get_cook_book(file_name): cook_book = {} with open(file_name, encoding='utf-8') as file: while True: dish_name = file.readline().strip() if not dish_name: break ingredients_count = int(file.readline().strip()) ingredients = [] for _ in range(ingredients_count): ingredient_line = file.readline().strip() ingredient_name, quantity, measure = ingredient_line.split(' | ') ingredients.append({ 'ingredient_name': ingredient_name, 'quantity': int(quantity), 'measure': measure }) cook_book[dish_name] = ingredients # пропускаем пустую строку между блюдами file.readline() return cook_book cook_book = get_cook_book('recipes.txt') print(cook_book)