我编写了一个小脚本,用于将文本文件内容与包含单词列表的另一个文本文件进行比较,但是运行它会说无法找到匹配项,我无法修复代码以成功地将它们与正确的结果进行比较。
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 :(得分: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")