I have dictionary and I want to sort frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical order comes first.
I wanted to use cmp function but apparently this function is deprecated in python 3.
This is what I've done:
dic = {'i': 2, 'like': 2, 'so': 1, 'coding': 1}
output = [key for key, value in sorted(
dic.items(), key=itemgetter(1, 0), reverse=True)]
print(output) // ['like', 'i', 'so', 'coding']
My desired output is ['i, 'like', 'coding', 'so' ]