Изменены data.txt, script.py

This commit is contained in:
Данил Русских 2025-11-06 15:49:09 +03:00
parent 05f0a87bd9
commit d7f0d26e66
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,4 @@
окно
поезд
где
почему

View File

@ -0,0 +1,14 @@
import re
with open("data.txt", 'r', encoding="UTF-8") as f:
text = f.read()
words = re.findall(r'\b\w+\b', text)
print(words)
sorted_words = sorted(words, key=len)
with open("output.txt", "+w", encoding="UTF-8") as f:
for word in sorted_words:
print(word)
f.write(word + "\n")