我已经看过其他类似的问题,但无法将答案应用于我的程序。目前频率按升序打印,我要更改什么以使其按降序打印?
from sys import argv
frequencies = {}
for ch in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
frequencies[ch] = 0
for filename in argv[1:]:
try:
f = open(filename)
except IOError:
print 'skipping unopenable', filename
continue
text = f.read()
f.close()
for ch in text:
if ch.isalpha():
ch = ch.upper()
frequencies[ch] = frequencies[ch] + 1
for ch in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
print ch, frequencies[ch]
提前致谢。