test01.txt 内
are
lol
test
hello
next
text02.txt 内
lol : positive
next : objective
sunday! : objective
are : objective
you : objective
going? : neutral
mail : objective
私のコード:
file1 = open('C://Users/Desktop/test01.txt')
file2 = open('C://Users/Desktop/test02.txt')
rfile1 = file1.readlines()
rfile2 = file2.read()
for test2 in rfile2.split("\n"):
testt2 = test2.split("\t")
for test1 in rfile1:
slsw1 = test1.split()
for wttest2 in testt2:
sttestt2 = wttest2.split(" ")
if sttestt2[0] in slsw1[0]:
sttestt2[0] = sttestt2[0].replace(sttestt2[0], "")
print sttestt2[0], ":", sttestt2[2]
予想された結果:
: positive
: objective
sunday! : objective
: objective
you : objective
going? : neutral
mail : objective
「test02.txt」の同じ単語をスペースに置き換えて結果を表示しようとしていますが、スペースのみを印刷しました。期待される結果と同じように、すべての結果を印刷したいと思います。
私は何か見落としてますか?なにか提案を?