第1个回答
用户4***62020.06.29回答如下图所示:
第2个回答
月亮照前窗2020.06.29回答7-1jmu-Java&Python-统计一段文字中的单词个数并按单词的字母顺序排序后输出(10分)现需要统计若干段文字(英文)中的不同单词数量。如果不同的单词数量不超过10个,则将所有单词输出(按字母顺序),否则输出前10个单词。注1:单词之间以空格(1个或多个空格)为间隔。注2:忽略空行或者空格行。注3:单词大小写敏感,即'word'与'WORD'是两个不同的单词。输入说明若干行英文,最后以!!!!!为结束。输出说明不同单词数量。然后输出前10个单词(按字母顺序),如果所有单词不超过10个,则将所有的单词输出。输入样例FailureisprobablythefortificationinyourpoleItislikeapeekyourwalletasthethiefwhenyouarethinkinghowtospendseveralhard-wonleptawhenyouArewonderingwhethernewmoneyithaslaidbackgroundBecauseofyou,thenattheheartofthemostlaxalertandmostlowawarenessandleftitgodsendfailed!!!!!输出样例49AreBecauseFailureItaalertandareasatwords=""whileTrue:a=input()ifa=="!!!!!":breakwords=words+""+awords=words.split()s={}foriinwords:ifiins:s[i]+=1else:s[i]=1s=list(s.items())s.sort(key=lambdax:x[0])print(len(s))iflen(s)<10:foriinrange(len(s)):word,count=s[i]print(word)else:foriinrange(10):word,count=s[i]print(word)