惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
P
Proofpoint News Feed
宝玉的分享
宝玉的分享
人人都是产品经理
人人都是产品经理
博客园_首页
爱范儿
爱范儿
博客园 - 叶小钗
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
MyScale Blog
MyScale Blog
阮一峰的网络日志
阮一峰的网络日志
IT之家
IT之家
Microsoft Security Blog
Microsoft Security Blog
Blog — PlanetScale
Blog — PlanetScale
博客园 - 【当耐特】
Y
Y Combinator Blog
量子位
博客园 - 三生石上(FineUI控件)
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
The Blog of Author Tim Ferriss
月光博客
月光博客
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
A
About on SuperTechFans

噜啦 - 函数

函数变量的作用域 - 噜啦 函数变量的作用域 - 噜啦 函数的可变长参数 - 噜啦 函数的可变长参数 - 噜啦 函数的定义和常用操作 && 课堂练习 - 噜啦
函数的定义和常用操作 && 课堂练习 - 噜啦
博主: 噜啦 · 2019-09-18 · via 噜啦 - 函数

函数的定义和常用操作 && 课堂练习

  • 发布时间:
  • 1624 次浏览
  • 902字数
  • 分类: Python笔记本
  1. 首页
  2. 正文  

代码

import re
def find_item( hero ):
    with open('sanguo.txt',encoding='GB18030') as f:
        data = f.read().replace('\n','')
        name_num=len(re.findall(hero,data))
    return name_num




#读取人物信息
name_dit = {}
with open('name.txt',encoding='utf-8') as f:
    for line in f:
        names = line.split('|')
        for n in names:
            name_num = find_item(n)
            name_dit[n] = name_num

name_sorted = sorted(name_dit.items(), key=lambda item: item[1], reverse=True)
print(name_sorted[0:10])

运行

相关文件

name.txt

sanguo.txt

weapon.txt

赞赏作者

如果觉得我的文章对你有用,请随意赞赏

函数的定义和常用操作 && 课堂练习

 •