在 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”中的相同单词并打印出来以查看结果,但我只打印出空格。我想按预期结果打印所有结果。
我错过了什么?有什么建议吗?