小编And*_*rew的帖子

我正在尝试计算txt文件中的所有字母,然后按降序显示

正如标题所说:

到目前为止,这是我在我的代码工作的地方,但我无法按顺序显示信息.目前它只是随机显示信息.

def frequencies(filename):
    infile=open(filename, 'r')
    wordcount={}
    content = infile.read()
    infile.close()
    counter = {}
    invalid = "‘'`,.?!:;-_\n—' '"

    for word in content:
        word = content.lower()
        for letter in word:
            if letter not in invalid:
                if letter not in counter:
                    counter[letter] = content.count(letter)
                    print('{:8} appears {} times.'.format(letter, counter[letter]))
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

python dictionary python-3.x display

6
推荐指数
2
解决办法
550
查看次数

标签 统计

dictionary ×1

display ×1

python ×1

python-3.x ×1