I am having trouble with the sorting by alphabetical order or possibly the displaying it that way part. it should do this Enter a sentence: An avocado a appeared 3 times
o appeared 2 times
c appeared 1 times d appeared 1 times n appeared 1 times v appeared 1 times
however mine does not sort by alphabetically after the number of times.
here is my code
sentence = input('Enter a sentence: ')
sentence = sentence.lower()
dictionary = {}
sort = {}
for n in sentence:
keys = dictionary.keys()
if n.isalpha():
if n in keys:
dictionary[n] += 1
else:
dictionary[n] = 1
sort = sorted(dictionary.items(), key = lambda letter:letter[1], reverse = True)
print()
print('Sentence Statistics:')
for x in sort:
if x[0].isalpha:
print(x[0], 'appeared', x[1],'times.')
else:
continue