组合数据类型,英文词频统计
Posted sjmhj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了组合数据类型,英文词频统计相关的知识,希望对你有一定的参考价值。
列表,元组,字典,集合的联系与区别:
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])
运行结果:
以上是关于组合数据类型,英文词频统计的主要内容,如果未能解决你的问题,请参考以下文章