sanguoyanyi.txt文档的准备,详见文件操作之extract_name
下面是weapon.txt的内容:
练习:提取相关武器,并统计出现的次数,然后排序
1 import re 2 3 4 def find_item2(weapon): 5 with open('sanguoyanyi.txt', encoding='utf-8') as f1: 6 data = f1.read().replace(' ', '') 7 weapon_num = len(re.findall(weapon, data)) 8 print("