问题描述
我编写了一个小脚本,将一个文本文件的内容与另一个包含单词列表的文本文件进行比较,但是运行该脚本表明找不到匹配项,我无法修复代码以成功将它们与正确的结果进行比较。
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")
1楼
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")