I have used sorted function to sort the dictionary by values, I am stuck at to how to sort the dict with keys if they have same values.
This is the final dict I created after sorting values :
{'hp': 2, 'technology': 2, 'teacher': 2, 'blodgett': 1, 'mo': 1, 'densetsu': 1, 'stafy': 1}
Now how do I achieve it to get i.e., sort keys lexicographical with same values.
hp
teacher
technology
blodgett
densetsu
mo
stafy
for w in sorted(wordFrequencyDict, key=wordFrequencyDict.get, reverse=True):
print(w, wordFrequencyDict[w])
is there any way to sort the dictionary by values in descending order and if values are same then sort is with key lexicographical in ascending.