字符串排序并输出

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

时间: 2024-08-03 10:24:53

字符串排序并输出的相关文章

UVA 156-Ananagrams(字符串排序按序输出无重复单词)

Ananagrams Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description  Ananagrams  Most crossword puzzle fans are used to anagrams--groups of words with the same letters in different orders--for example OPTS, SPO

JAVA-从题目看算法,将输入字符串进行排序并输出

来看一个排列的例子,它所做的工作是将输入的一个字符串中的所有元素进行排序并输出,例如:你给出的参数是"abc" 则程序会输出:abc acb bac bca cab cba 这是一个典型的可用递归算法来实现的例子,我们来看一下利用递归的2种不同解法. 1.典型递归元素交换的算法 (1)算法的出口在于:low=high也就是现在给出的排列元素只有一个时. (2)算法的逼近过程:先确定排列的第一位元素,也就是循环中i所代表的元素. package test; import java.uti

将字符串中单词经排序后输出

思路 先将字符串中的单词分割保存至二维数组中,再经排序后输出.水题,直接上代码了. 代码 /************************************************************************* > File Name: words_sort.c > Author: KrisChou > Mail:[email protected] > Created Time: Sun 24 Aug 2014 08:41:42 PM CST *****

输入password登录到主界面,录入学生编号,排序后输出

n 题目:输入password登录到主界面,录入学生编号,排序后输出 n 1.  语言和环境 A.实现语言 C语言 B.环境要求 VC++ 6.0 n 2.  要求 请编写一个C语言程序.将若干学生编号按字母顺序(由小到大)输出. 程序的功能要求例如以下: 1)  输入password"admin",正确则进入主界面,错误则直接推出(exit(0)): 2)从键盘输入5个学生编号"BJS1001","BJS2001"."BJS1011&

Openjudge-计算概论(A)-字符串排序

描述 参考整数排序方法,设计一种为字符串排序的算法,将字符串从小到大输出 输入 第一行为测试数据组数t, 后面跟着t组数据.每组数据第一行是n,表示这组数据有n行字符串,接下来是要排序的n行字符串.每行字符串的字符个数不会大于200, n < 100. 输出 对于每组数据,输出排好序的字符串,每组输出后要多输出一个空行 样例输入 2 2 Hello World 4 I Love C Language! 样例输出 Hello World C I Language! Love思路:这题可以把它们全部

gets()、puts()函数。字符串函数。字符串排序的例子。

1.实例程序:string.c的程序: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 #include<stdio.h> #define MSG "YOU MUST have many talents .tell me some." #define LIM 5 #define LINELEN 81 int main() { char name[LINELEN]; char

关于字符串排序合并的问题

今天遇到了一个问题,题目大意是输入两个字符串,然后给这两个字符串按照ASCII码从小到大进行排序,最后在将两个字符串合并,要求删除其中相同的字符.一开始的时候感觉挺简单的一道题,但是做起来还是小毛病挺多的.还是直接看代码吧,代码里面的注释有许多需要注意的地方. 1 #include<stdio.h> 2 #include<string.h> 3 void sort(char *p) //给字符串排序,参数为字符串首地址 4 { 5 char temp; 6 char *head,*

九度OJ 1066 字符串排序

题目1066:字符串排序 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4919 解决:1983 题目描述: 输入一个长度不超过20的字符串,对所输入的字符串,按照ASCII码的大小从小到大进行排序,请输出排序后的结果 输入: 一个字符串,其长度n<=20 输出: 输入样例可能有多组,对于每组测试样例, 按照ASCII码的大小对输入的字符串从小到大进行排序,输出排序后的结果 样例输入: dcba 样例输出: abcd #include<stdio.h> #include<

字符串排序

描述 编写一个程序,将输入字符串中的字符按如下规则排序. 规则1:英文字母从A到Z排列,不区分大小写. 如,输入:Type 输出:epTy 规则2:同一个英文字母的大小写同时存在时,按照输入顺序排列. 如,输入:BabA 输出:aABb 规则3:非英文字母的其它字符保持原来的位置. 如,输入:By?e 输出:Be?y 样例: 输入: A Famous Saying: Much Ado About Nothing(2012/8). 输出: A aaAAbc dFgghh: iimM nNn ooo