I have a dictionary in Python like this:
{'c': 3, 'b': 3, 'aa': 2, 'a': 2}
and I want to print it like this:
b
c
a
aa
I need to sort the dictionary first by the second key and if there are any collisions, sort them lexicographically.
I have searched and can't find any solutions. Here is what I have already tried:
temp = {'c' : 3, 'b': 3, 'aa' : 2, 'a' : 2}
results = []
for key, value in temp.items():
results.append([key, value])
results.sort(key = operator.itemgetter(1,0), reverse = True)
for result in results:
print(result)
This doesn't work though it results in this:
c
b
aa
a
The output should be:
b
c
a
aa
I appreciate any help! (Note: using Python 3)