I know it wasn't well explained in the title so I'll try and do a better job here. I want to sort a dictionary's keys by their respective values, and then sort any keys with the same value alphabetically. What is the best way to do this, ideally without the use of modules?
Does python do this automatically with a sort like:
sorted(dictionary.items(), key=lambda x: x[1])
I tried the above code and it seemed to work but I couldn't tell if it was just coincidence or not. I couldn't find anything in the docs and I need to know if it will always work.
Starting dictionary:
dictionary = {'d':2, 'c':1, 'a':2, 'b':3}
Sorted by value:
['c', 'd', 'a', 'b']
(1, 2, 2, 3)
Items with the same value sorted alphabetically:
['c', 'a', 'd', 'b']
(1, 2, 2, 3)