1. 程式人生 > >組合數據類型,英文詞頻統計

組合數據類型,英文詞頻統計

for meet cap pro 字典 適合 操作 技術分享 capital

列表,元組,字典,集合的聯系與區別:
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])

運行結果:

技術分享圖片




組合數據類型,英文詞頻統計