码迷,mamicode.com
首页 > 编程语言 > 详细

字符串排序并输出

时间:2017-09-27 16:14:47      阅读:212      评论:0      收藏:0      [点我收藏+]

标签: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])#输出排名前十五的元组

字符串排序并输出

标签:use   make   列表   put   集合   lin   where   path   排名   

原文地址:http://www.cnblogs.com/xy123ing/p/7602023.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!