Như tiêu đề nói:Tôi đang cố gắng để đếm tất cả các chữ trong một file txt sau đó hiển thị theo thứ tự giảm dần
Cho đến nay đây là nơi tôi đang ở mã của tôi không làm việc tuy nhiên tôi đang gặp khó khăn hiển thị thông tin theo thứ tự. Hiện tại nó chỉ hiển thị thông tin một cách ngẫu nhiên.
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]))
Mọi trợ giúp sẽ được đánh giá cao.