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

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

 

 

列表,元组,字典,集合的联系与区别: 1,列表的增删改查的时间消耗随着元素的增加而增加,当元素大的时候比较浪费时间 3、元组只能查,不能增删改,可以保证数据的安全性,因为可操作性较低,资源占用也较少,适合用来存储经常查但不经常修改的数据 4、集合最重要的一个特性就是去重,适合用于存储不重复的key 5、列表元组集合都可以以进行数据的增删改查 6、字典存放的数据是key:value类型的,通过key可以非常快速的查找到对应的value.但是占用的内存和空间较大,是一种空间换时间的数据类型
英文歌词:
strgc = '''Dear god, I know that she?s out there...the one I?m suppose to share my whole life with. And in time...you?ll show her to me. Will you take care of her, comfort her, and protect her...until that day we Meet. And let her know...my heart...is beating with hers. In a dream I hold you close Embracing you with my hands You gazed at me with eyes full of love And made me understand That I was meant to share it with you My heart my mind my soul Then I open my eyes And all I see reality shows I?m alone But I know someday that you?ll be by my side Cause I know god?s just waiting till the time is right God will you keep her safe from the thunderstorm When the day?s cold will you keep her warm When the darkness falls will you please shine her the way God will you let her know that I love her so When theres no one there that she?s not alone Just close her eyes and let her know My heart is beating with hers So I prayed until that day (prayed until that day) When our hearts will beat as one (when our hearts hearts will beat as one) I will wait so patiently (patiently) For that day to come (for that day to come) I know someday that you?ll be by my side Cause I know god?s just waiting till the time is right God will you keep her safe from the thunderstorm When the day?s cold will you keep her warm When the darkness falls will you please shine her the way (shine he the way) God will you let her know that I love her so When theres no one there that she?s? not alone Just close her eyes and let her know My heart is beating with hers Is beating with hers (ooo) My heart is beating with hers (oooo) It?s beating with hers God will you keep her safe from the thunderstorm When the day?s cold will you keep her warm When the darkness falls will you please shine her the way God will you let her know that I love her so When theres no one there that she?s not alone Just close her eyes and let her know My heart is beating with hers Oh~~~ it?s beating with hers'''
 
strList = strgc.split(' ')#词频统计 print(len(strList),max(strList))#取属性 print(strList.sort())#排序 print(strgc.upper())# 将歌词全部大写 print(strgc.lower())#将歌词全部小写 print(strgc.capitalize())#首字母大写其他小写 print(strgc.title())#首字母大写 print(strgc.swapcase)#大小写互换 print(strgc[1:10])#取片段 print(strgc.index('out'))#取元素的索引 print(strgc.count('you'))#计数 运行结果:

 

strList = strgc.split(' ')#分隔单词 print(strList) print(set(strList)) for word in strList:#单词个数     print(word,strList.count(word)) 运行结果:

用Dict统计单词出现的次数

strSet = set(strList) print(len(strSet),strSet) strDict = { } for word in strSet:     strDict[word] = strList.count(word) print(strDict['strgc']) print(len(strDict),strDict)

运行结果:

列表,元组,字典,集合的遍历 myList = list(range(10)) myTuple = tuple(range(10)) mySet = set(range(10)) myDict = {'hey': '1', 'hai': '2', 'why': '3'} for i in myList:     print(i, end="") print() for j in myTuple:     print(j, end="") print() for k in mySet:     print(k, end="") print() for l in myDict.keys():     print(l, myDict[l]) 运行结果:

 

 
 

 

 

 

 

转载于:https://www.cnblogs.com/SJMHJ/p/9679877.html

你可能感兴趣的文章
Mysql支持的数据类型
查看>>
openSuse beginner
查看>>
Codeforces 620E(线段树+dfs序+状态压缩)
查看>>
Windows7中双击py文件运行程序
查看>>
Market entry case
查看>>
bzoj1230 开关灯 线段树
查看>>
LinearLayout
查看>>
学习python:day1
查看>>
css3动画属性
查看>>
第九次团队作业-测试报告与用户使用手册
查看>>
Equal Sides Of An Array
查看>>
CentOS笔记-用户和用户组管理
查看>>
Mongodb 基本命令
查看>>
Qt中QTableView中加入Check列实现
查看>>
“富豪相亲大会”究竟迷失了什么?
查看>>
控制文件的备份与恢复
查看>>
返回代码hdu 2054 A==B?
查看>>
Flink独立集群1
查看>>
iOS 8 地图
查看>>
20165235 第八周课下补做
查看>>