You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
630 B
20 lines
630 B
2 months ago
|
from collections import Counter
|
||
|
|
||
|
# 读取新闻标题文件
|
||
|
with open('aoyun.txt', 'r', encoding='utf-8') as f:
|
||
|
danmu_all = f.readlines()
|
||
|
|
||
|
# 筛选包含关键词的表题
|
||
|
keywords = ['冠军','夺冠','金牌','金','冠','胜利','取胜','连胜','赢','战胜','荣耀']
|
||
|
ai_danmu = [danmu for danmu in danmu_all if any(keyword in danmu for keyword in keywords)]
|
||
|
|
||
|
num = Counter(ai_danmu)
|
||
|
most_common = num.most_common(30)
|
||
|
|
||
|
print("输出含有关键词的新闻标题:")
|
||
|
i = 0
|
||
|
for content,count in most_common:
|
||
|
print(f"{content.strip()}")
|
||
|
i += 1
|
||
|
|
||
|
print("含有关键词的新闻标题有",i,'个')
|