博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
组合数据类型练习,英文词频统计实例上
阅读量:6308 次
发布时间:2019-06-22

本文共 1714 字,大约阅读时间需要 5 分钟。

字典实例:建立学生学号成绩字典,做增删改查遍历操作。

d={'01':'80','02':'70','03':'76','04':'86','05':'82'}

print(d.keys())
print(d.values())
d['08']=98
d['03']=99
d.pop('02')
print(d.get('07'))
print(d)

列表,元组,字典,集合的遍历。

总结列表,元组,字典,集合的联系与区别。

str=list('123112312')

tu=tuple('abcdrfghj')
s=set([5,4,3,1,6])
d=dict(zip(tu,str))
print(str)
print(tu)
print(s)
print(d)
for i in str:
print(i)
for j in tu:
print(j)
for h in s:
print(h)
for k in d:
print(k,d[k])

 

 

英文词频统计实例

待分析字符串

分解提取单词

大小写 txt.lower()

分隔符'.,:;?!-_’

单词列表

单词计数字典

 

new='''After the Winter - Lenka

When the rain is pourin' down

"And there are snowflakes on your cheeks"

When your heart is frozen over

And there is a sea lost sun in weeks

Just remember,

Just remember,

After the winter comes the spring

That is when the blue birds

Starts to sing

And you can always count on this

After the winter comes the spring

When the trees have lost the color

And the sky is full of fears

When you feel you are going under

And your eyes are full of tears

When the bells are all hiding

And you are hiding too

Oh, darling just remember

That everything will soon be new

After the winter comes the spring

That is when the blue birds

Start to use their wings

And you can always count on this

After the winter comes the spring

Just remember,

Just remember,

Just remember,

Just remember,

After the winter comes the spring.

That is when the blue birds.

Starts to sing.

And you can always count on this

After the winter comes the spring

After the winter comes the spring'''

new = new.lower()

for i in ',."':
    new = new.replace(i,' ')
new = new.split(' ')
words = set(new)
d = {}
for i in words:
    d[i] = new.count(i)

for i in d:

    print('{0:<15}{1}'.format(i,d[i]))

 

 

转载于:https://www.cnblogs.com/1257-/p/7573369.html

你可能感兴趣的文章
http2-head compression
查看>>
C# 命名空间
查看>>
订餐系统之同步美团商家订单
查看>>
使用ArrayList时设置初始容量的重要性
查看>>
Java Web-----JSP与Servlet(一)
查看>>
Maven搭建SpringMVC+Mybatis项目详解
查看>>
关于量子理论:最初无意的简化,和一些人有意的强化和放大
查看>>
CentOS 6.9通过RPM安装EPEL源(http://dl.fedoraproject.org)
查看>>
“区块链”并没有什么特别之处
查看>>
没有功能需求设计文档?对不起,拒绝开发!
查看>>
4星|《先发影响力》:影响与反影响相关的有趣的心理学研究综述
查看>>
IE8调用window.open导出EXCEL文件题目
查看>>
python之 列表常用方法
查看>>
vue-cli脚手架的搭建
查看>>
在网页中加入百度搜索框实例代码
查看>>
在Flex中动态设置icon属性
查看>>
采集音频和摄像头视频并实时H264编码及AAC编码
查看>>
3星|《三联生活周刊》2017年39期:英国皇家助产士学会于2017年5月悄悄修改了政策,不再鼓励孕妇自然分娩了...
查看>>
linux查看命令是由哪个软件包提供的
查看>>
高级Linux工程师常用软件清单
查看>>