I have a dictionary in the following format :-
d = { 'x' : 1, 'y' : 2, 'z' : 1, 'a' : 3 }
How can I print this to shell in the following format :-
alphabet number
----------------------
a 3
y 2
x 1
z 1
My code to print the dictionary to shell :- (ignoring printing 'alphabet,'number' and '-----')
for key,value in sorted(d.items()):
print("{:>10}{:>20}".format(key,value))
So I know how to use the .format method to print the dictionary, but looking at the desired output I cannot understand how to print the dictionary by largest value to the smallest value.
Any suggestions?!