前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >全国计算机等级考试二级python及复习总结2020.9.7

全国计算机等级考试二级python及复习总结2020.9.7

作者头像
用户7138673
发布2022-09-21 11:13:26
2820
发布2022-09-21 11:13:26
举报
文章被收录于专栏:大大的小数据

开干

1、python类型属性、函数考点

2、计算40个大题的代码中函数出现次数。

代码语言:javascript
复制
import jieba

f = open("新建文本文档.txt", "r", encoding="utf-8")
lines = f.readlines()
f.close()

d = {}
for line in lines:
    wordList = jieba.lcut(line)  # 用结巴分词,对每行内容进行分词
    for word in wordList:
        if len(word) < 3:
            continue
        else:
            d[word] = d.get(word, 0) + 1
ls = list(d.items())
ls.sort(key=lambda x: x[1], reverse=True)  # 按照词频由高到低排序

f = open('out2.txt', 'w', encoding="utf-8")
for i in range(len(ls)):
    f.write('{}:{}\n'.format(ls[i][0], ls[i][1]))
f.close()

结果

line:156 #行,遍历文件为行

for:140 #for i in rang,for i in X 循环遍历

txt:121 #大量文本

open:84 #打开大量文本格式

print:75 #打印测试

close:71 #关闭文件 f.close()

encoding:59 #encoding ="utf-8"以UTF-8格式读取文件

utf:56 #encoding ="utf-8"以UTF-8格式读取文件

format:49 #格式化字符串

split:39 #line.split(",")以逗号或者空格分隔字符串

append:38 #列表追加字符串

len:38 #长度

range:37 #for in range 循环遍历

row:36 #for row in ls:循环遍历行

write:30 #f.write('\n') # 换行写入

jieba:29 #结巴分词库

key:27 #字典、值

replace:26 #替换字符串内容

readlines:25 #读取文件lines = f.readlines()

lines:23 #读取文件lines = f.readlines()

count:22 #计数

list:21 #列表

get:20 #words[w] = words.get(w,0)+1,循环遍历后字典累加计数

else:20 #if else

word:20

flag:19

True:19

strip:18

cnt:16

import:16

item:16

reverse:16

items:16

平均值:16

join:15

sort:15

lambda:15

res:15

lcut:14

input:14

end:14

words:14

with:14

def:14

...:13

alt:13

字符串:13

read:12

data:12

最大值:12

elif:12

总成绩:12

numbers:11

sum:11

urls:10

csv:10

file:10

int:10

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-09-07,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 大大的小数据 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档