Добавление строки в текстовый файл добавляет только первую букву PythonPython

Программы на Python
Anonymous
Добавление строки в текстовый файл добавляет только первую букву Python

Сообщение Anonymous »

Код: Выделить всё

with open("words_alpha.txt", 'r') as f:
your_result = [line.split(',') for line in f.read().splitlines()]

for i in your_result:
for word in i:
x = len(word)
print(word)
if x == 1:
with open("1.txt", "a") as myfile:
myfile.write(word)
if x == 2:
with open("2.txt", "a") as myfile:
myfile.write(word)

if x == 3:
with open("3.txt", "a") as myfile:
myfile.write(word)

if x == 4:
with open("4.txt", "a") as myfile:
myfile.write(word)
if x == 5:
with open("5.txt", "a") as myfile:
myfile.write(word)

if x == 6:
with open("6.txt", "a") as myfile:
myfile.write(word)

if x == 7:
with open("7.txt", "a") as myfile:
myfile.write(word)
if x == 8:
with open("8.txt", "a") as myfile:
myfile.write(word)

if x == 9:
with open("9.txt", "a") as myfile:
myfile.write(word)

if x == 10:
with open("10.txt", "a") as myfile:
myfile.write(word)
if x == 11:
with open("11.txt", "a") as myfile:
myfile.write(word)

if x == 12:
with open("12.txt", "a") as myfile:
myfile.write(word)r
код правильно печатает слово из списка слов, но при добавлении той же переменной в каждый файл добавляется только первая буква. код выводит слова построчно, но при добавлении они отображаются только как набор букв. Текстовый файл альфа-слов представляет собой список слов со словами в каждой строке. я хочу отсортировать слова по количеству букв

Подробнее здесь: https://stackoverflow.com/questions/786 ... ter-python

Вернуться в «Python»