“test_tweet1.txt”中有两句话
@francesco_con40 2nd worst QB. DEFINITELY Tony Romo. The man who likes to share the ball with everyone. Including the other team.
@mariakaykay aga tayo tomorrow ah. :) Good night, Ces. Love you! >:D<
在“个人.txt”中
The Game (rapper)
The Notorious B.I.G.
The Undertaker
Thor
Tiësto
Timbaland
T.I.
Tom Cruise
Tony Romo
Trajan
Triple H
我的代码:
import re
popular_person = open('C:/Users/Personal.txt')
rpopular_person = popular_person.read()
file1 = open("C:/Users/test_tweet1.txt").readlines()
array = []
count1 = 0
for line in file1:
array.append(line)
count1 = count1 + 1
print "\n",count1, line
ltext1 = line.split(" ")
for i,text in enumerate(ltext1):
if text in rpopular_person:
print text
text2 = ' '.join(ltext1)
代码结果显示:
1 @francesco_con40 2nd worst QB. DEFINITELY Tony Romo. The man who likes to share the ball with everyone. Including the other team.
Tony
The
man
to
the
the
2 @mariakaykay aga tayo tomorrow ah. :) Good night, Ces. Love you! >:D<
aga
我试图将“test_tweet1.txt”中的单词与“Personal.txt”匹配。
预期结果:
Tony
Romo
有什么建议吗?