「test.txt」には2つのsentnecがあります
文 1 = 文は、1 つまたは複数の単語で構成される文法単位です。
文2 =文は、正書法用語のみで定義することもできます。
count_line = 0
for line in open('C:/Users/Desktop/test.txt'):
count_line = count_line +1
fields = line.rstrip('\n').split('\t')
##print count_line, fields
file = open('C:/Users/Desktop/test_words.txt', 'w+')
count_word = 0
for words in fields:
wordsplit = words.split()
for word in wordsplit:
count_word = count_word + 1
print count_word, word
file.write(str(count_word) + " " + word + '\n')
file.close()
「test_words.txt」での私の結果は、2 番目の文の単語のみを示しました。
1 A
2 sentence
3 can
4 also
5 be
6 defined
7 in
8 orthographic
9 terms
10 alone.
最初の文の単語も書き、2 番目の文 "test_words.txt" の単語を続けるにはどうすればよいですか?
なにか提案を?