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

英文詞頻統計預備,組合數據類型練習

life ril 對象 1-1 com please moment ppi hat

1.實例: 下載一首英文的歌詞或文章,將所有,.?!等替換為空格,將所有大寫轉換為小寫,統計某幾個單詞出現的次數,分隔出一個一個的單詞。

lyrics=‘‘‘Waking up I see that everything is okay
The first time in my life and now it‘s so great
Slowing down I look around and I am so amazed
I think about the little things that make life great
I wouldn‘t change a thing about it
This is the best feeling
This innocence is brilliant, I hope that it will stay
This moment is perfect, please don‘t go away
I need you now
And I‘ll hold on to it, don‘t you let it pass you by
I found a place so safe, not a single tear
The first time in my life and now it‘s so clear
Feel calm, I belong, I‘m so happy here
It‘s so strong and now I let myself be sincere
I wouldn‘t change a thing about it
This is the best feeling
This innocence is brilliant, I hope that it will stay
This moment is perfect, please don‘t go away
I need you now
And I‘ll hold on to it, don‘t you let it pass you by
It‘s the state of bliss you think you‘re dreaming
It‘s the happiness inside that you‘re feeling
It‘s so beautiful, it makes you wanna cry
It‘s the state of bliss you think you‘re dreaming
It‘s the happiness inside that you‘re feeling
It‘s so beautiful, it makes you wanna cry
It‘s so beautiful, it makes you wanna cry
This innocence is brilliant, it makes you wanna cry
This innocence is brilliant, please don‘t go away
‘Cause I need you now
And I‘ll hold on to it, don‘t you let it pass you by
This innocence is brilliant, it‘s so beautiful, it‘s so beautiful
This moment is perfect, please don‘t go away
I need you now, it makes me wanna cry
And I‘ll hold on to it, don‘t you let it pass you by
‘‘‘ lyrics=lyrics.lower() lyrics=lyrics.replace(,, ) print(lyrics) words=lyrics.split( ) print(words)

運行結果為:

技術分享

2.列表實例:由字符串創建一個作業評分列表,做增刪改查詢統計遍歷操作。例如,查詢第一個3分的下標,統計1分的同學有多少個,3分的同學有多少個等。

ls=list(12134165135241335363)
for i in range (len(ls)):
    ls[i]=int(ls[i])
print(ls)
print(ls.index(3))
print
(ls.count(1)) print(ls.count(3))

運行結果為:

技術分享

3.簡要描述列表與元組的異同。

答:元組和列表基本一樣,列表與元組都是容器,是一系列的對象,二者都可以包含任意類型的元素甚至可以是一個序列,還可以包含元素的順序

但是列表可以修改列表元素,而元組不可以修改元素

英文詞頻統計預備,組合數據類型練習