python 句子中字母出现的次数
求助,谢谢。。http://hhscp.org/programming/assignment/c06characterdistributionhttp://hhscp.o...
求助,谢谢。。
http://hhscp.org/programming/assignment/c06characterdistribution
http://hhscp.org/programming/assignment/c07stringjumble
http://hhscp.org/programming/assignment/c09exceptions
http://hhscp.org/programming/assignment/tkinter 展开
http://hhscp.org/programming/assignment/c06characterdistribution
http://hhscp.org/programming/assignment/c07stringjumble
http://hhscp.org/programming/assignment/c09exceptions
http://hhscp.org/programming/assignment/tkinter 展开
展开全部
第一题:
import re
import string
inText = raw_input('Please enter a string of text (the bigger the better): ')
outText = inText.lower()
outText = re.sub(r"[^a-z]","", outText)
count, letter = [], []
for l in string.ascii_lowercase:
n = outText.count(l)
if n != 0:
count.append(n)
letter.append(l)
map = sorted(zip(count, letter), key=lambda x:(x[0]), reverse=True)
print 'The distribution of characters in "' + inText + '" is:'
for c in map:
print c[1] * c[0]
更多追问追答
追问
求教剩下两题
会追加分数
追答
自己动手学习最好。
第二题
inText = raw_input('Please enter a string of text (the bigger the better): ')
print 'The distribution of characters in "' + inText + '" is:'
outText1 = "";
for l in inText[::-1]:
outText1 += l;
print outText1
outText2 = "";
for l in inText.split(" ")[::-1]:
if outText2 == "":
outText2 = l;
else:
outText2 += " " + l;
print outText2
outText3 = "";
for l in inText.split(" "):
if outText3 == "":
outText3 = l[::-1];
else:
outText3 += " " + l[::-1];
print outText3
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询