/
denbertu
/
Open_Read_Write_File_Homework
Обзор
Документация
Войти
/
denbertu
/
Open_Read_Write_File_Homework
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
exercise1.py
20 строк
704 B
Denis Klochikhin
Exercises corrected
28 сен 2025, 18:33
28 сен 2025, 18:33
7ab93c7
Код
Авторство
О чём код?
def recipe_dict_from_txt(txt): cook_book = {} with open(txt, 'r+', encoding='utf-8') as f: lines = f.readlines() dish = "" for line in lines: if not line.strip(): continue if line.strip().isdigit(): continue if '|' in line: splitted = line.strip().split("|") ings = {'ingredient_name': splitted[0], 'quantity': int(splitted[1]), 'measure': splitted[2]} cook_book[dish].append(ings) continue cook_book.setdefault(line.strip(), []) dish = line.strip() return cook_book # print(recipe_dict_from_txt('recipes.txt'))