首页 > 编程语言 > 详细

字符串排序并输出

时间:2017-09-27 15:47:21      阅读:285      评论:0      收藏:0      [点我收藏+]

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

字符串排序并输出

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!