/
Cosm03
/
cook_book
Обзор
Документация
Войти
/
Cosm03
/
cook_book
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
task3.py
25 строк
789 B
Cosm03
Task 3
22 май 2026, 13:14
22 май 2026, 13:14
647cf08
Код
Авторство
О чём код?
def count_lines(file_path): with open(file_path, encoding="utf-8") as file: return sum(1 for _ in file) def merge_files(file_names, output_file): files_info = [] for file_name in file_names: line_count = count_lines(file_name) files_info.append((line_count, file_name)) files_info.sort() with open(output_file, "w", encoding="utf-8") as result_file: for line_count, file_name in files_info: with open(file_name, encoding="utf-8") as current_file: result_file.write(f"{file_name}\n") result_file.write(f"{line_count}\n") result_file.writelines(current_file) if __name__ == "__main__": file_names = ["1.txt", "2.txt", "3.txt"] merge_files(file_names, "result.txt")