「test_tweet1.txt」には2つの文があります
@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<
「Personal.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
なにか提案を?