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

你可能感兴趣的文章
【OC语法要闻速览】一、方法调用
查看>>
Git-命令行-删除本地和远程分支
查看>>
本文将介绍“数据计算”环节中常用的三种分布式计算组件——Hadoop、Storm以及Spark。...
查看>>
顺序图【6】--☆☆
查看>>
Docker Swarm 让你事半功倍
查看>>
string.Format字符串格式说明
查看>>
[转]IC行业的牛人
查看>>
javaScript事件(四)event的公共成员(属性和方法)
查看>>
linux系统常用命令
查看>>
在 Word 中的受支持的区域设置标识符的列表
查看>>
Caffe + Ubuntu 14.04 64bit + CUDA 6.5 配置说明2
查看>>
An easy to use android color picker library
查看>>
Oracle SID爆破工具SidGuess
查看>>
批处理常用命令总结2
查看>>
解读ASP.NET 5 & MVC6系列(9):日志框架
查看>>
MyEclipse生成WAR包并在Tomcat下部署发布(转发)
查看>>
Android -- 自定义View小Demo,绘制钟表时间(一)
查看>>
信息检索Reading List
查看>>
JavaWeb_JavaEE_命名规则
查看>>
申小雨命案审理延期至3月5日 警方将翻译嫌犯口供
查看>>