python字母频率统计

【问题描述】编写程序从标准输入中读入一段英文,统计其中小写字母出现次数,并按照从小到大的顺序以柱状图的形式显示其出现次数,出现次数为0的不输出。
【输入形式】在标准输入上输入一段英文文章(可能有一行,也可能有多行),在新的一行的开头输入ctrl+z键表示结束。
【输出形式】在屏幕上按照从小到大的顺序输出表示每个小写字母出现次数的柱状图(以“”字符表示柱状图,空白处用空格字符表示,某个小写字母出现多少次,就显示多少“”字符;柱状图的高度以出现最多的字母次数为准;出现次数为0的不输出),不输出相对应的小写字母。若文章中没有小写字母,则什么都不输出。
【样例输入】
The computing world has undergone a
revolution since the publication of
The C Programming Language in 1978.
【样例输出】

img

【样例说明】
字母b、f、v和w只出现了一次,所以最左方高度为1的柱状表示这四个字母的出现次数。出现次数最多的是字母n,所以柱状图的高度为9个字符,在图的最右边。没有出现的字母,其出现次数忽略,没有显示。
【评分标准】
该题要求按照从小到大的顺序输出柱状图表示的字母出现次数,共有5个测试点。
的星号应该是往右堆的,但我试了好几次都是往左怎么办?

统计之后你会得到一个最大值,以这个最大值作为标准,其他的图都先补齐空格,然后再输出星号

from collections import Counter

s = """The computing world has undergone a
revolution since the publication of
The C Programming Language in 1978.
"""

d = [i for i in s if 'z'>= i >= 'a']
res = Counter(d)
v = sorted(res.values())
le = len(v)
ma = max(v)

l = []
for i in v:
    e = "*" * i + ' ' * (le - i)
    l.append(list(e))
for j in range(ma, -1, -1):
    for i in range(le):
        print(l[i][j], end='')
    print()

string = '''The computing world has undergone a
revolution since the publication of
The C Programming Language in 1978.'''

dicABC = {chr(ord('a')+i):0 for i in range(26)}
for c in string:
    if 'a'<=c<'z': dicABC[c]+=1
lstABC = sorted(dicABC.items(),key=lambda x:x[1])
lstABC = [i[1] for i in lstABC if i[1]!=0]

n = len(lstABC)
result = []
count = 0
for i in range(lstABC[-1],0,-1):
    if i in lstABC:
        t = lstABC.count(i)
        if t==0: continue
        count += t
        result.append(' '*(n-count)+'*'*count)

for i in result: print(i)

输出:

                   *
                 ***
                ****
              ******
            ********
          **********
       *************
    ****************
********************