2017-02-08 8 views
0

テキストファイルの内容を単語リストを含む別のテキストファイルと比較する小さなスクリプトを作成しましたが、実行すると一致が見つからないと表示されます。コードを修正して正常に比較することはできません結果。テキストファイルの内容を比較する

wordlist = input("What is your word list called?") 
f = open(wordlist) 
t = f.readlines() 
l = ''.join(t).lower() 
chatlog = input("What is your chat log called?") 
with open(chatlog) as f: 
    found = False 
    for line in f: 
     line = line.lower() 
     if l in line: 
      print(line) 
      found = True 
    if not found: 
     print("not here") 

答えて

0
wordlist = input("What is your word list called?") 
f = open(wordlist) 
l = set(w.strip().lower() for w in f) 
chatlog = input("What is your chat log called?") 
with open(chatlog) as f: 
    found = False 
    for line in f: 
     line = line.lower() 
     if any(w in line for w in l): 
      print(line) 
      found = True 
    if not found: 
     print("not here") 
関連する問題