字串排序並輸出

來源:互聯網
上載者:User

標籤:use   make   列表   put   集合   lin   where   path   排名   

story=‘‘‘I‘m hurting, baby, I‘m broken down

I need your loving, loving, I need it now

When I‘m without you

I‘m something weak

You got me begging

Begging, I‘m on my knees

I don‘t wanna be needing your love

I just wanna be deep in your love

And it‘s killing me when you‘re away

Ooh, baby,

‘Cause I really don‘t care where you are

I just wanna be there where you are

And I gotta get one little taste

Your sugar

Yes, please

Won‘t you come and put it down on me

I‘m right here, ‘cause I need

Little love and little sympathy

Yeah you show me good loving

Make it alright

Need a little sweetness in my life

Your sugar

Yes, please

Won‘t you come and put it down on me

My broken pieces

You pick them up

Don‘t leave me hanging, hanging

Come give me some

When I‘m without ya

I‘m so insecure

You are the one thing

The one thing, I‘m living for

I don‘t wanna be needing your love

I just wanna be deep in your love

And it‘s killing me when you‘re away

Ooh, baby, ‘‘‘
story = story.lower()#字串變小寫
for i in ‘,.?!‘:
story =story.replace(i,‘ ‘)
story = story.split(‘ ‘)#字串變單字清單
exp = {‘ ‘,‘i"m‘,‘and‘,‘it‘,‘don"t‘}

dic = {}
keys = set(story)-exp#取得文法成分的單詞的鍵的集合
for a in keys:
dic[a] =story.count(a)

b = list(dic.items())
b.sort(key= lambda x:x[1],reverse=True)#列表從大到小排序

for i in range(15):
print(b[i])#輸出排名前十五的元組

字串排序並輸出

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.