例如,我有2个列表:
a = ['podcast', 'podcasts', 'history', 'gossip', 'finance', 'business', 'kids', 'motivation', 'news', 'investing']
b = ['podcast', 'history', 'gossip', 'finance', 'kids', 'motivation', 'investing']
我希望找到列表a
中不在列表b
中的项。
我尝试这样做:
c = []
for _ in a:
if _ not in b:
c.append(_)
我尝试的所有方法都以这样的结果结束:
![image](https://istack.dev59.com/pKf7h.webp)
一开始,我有一个包含关键词的文本文件:
podcast
podcasts
history
gossip
finance
对于几乎所有关键字,我都有包含信息的文本文件:
podcast.txt
podcasts.txt
history.txt
我需要找出我缺少的文件 我像这样加载关键字列表:
a = []
with open("keywords.txt", "r") as f:
text = f.read().split("\n")
for k in text:
a.append(k)
b = [e.replace(".txt", "") for e in os.listdir("profiles/")]
[i for i in a if i not in b]
- Onyambu