/
nichemuche
/
write_read_files
Обзор
Документация
Войти
/
nichemuche
/
write_read_files
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
task1.py
29 строк
923 B
nichemuche
task1
21 май 2025, 17:15
21 май 2025, 17:15
01913ca
Код
Авторство
О чём код?
def read_cook_book(filename): cook_book = {} with open(filename, 'r', encoding='utf-8') as file: while True: dish_name = file.readline().strip() if not dish_name: break ingredient_count = int(file.readline().strip()) ingredients = [] for _ in range(ingredient_count): ingredient_info = file.readline().strip().split(' | ') ingredient = { 'ingredient_name': ingredient_info[0], 'quantity': int(ingredient_info[1]), 'measure': ingredient_info[2] } ingredients.append(ingredient) cook_book[dish_name] = ingredients file.readline() return cook_book cook_book = read_cook_book('recipes.txt') print(cook_book)