I am new to Python, I have seen many examples but not a good summary of examples. Here are the 4 things that I want to get done. Thanks for your help.
mydict = {'carl':40,
'alan':2,
'bob':1,
'danny':3}
I wanted to use the following to access the dict elements:
for key in sorted(mydict.keys()):
print(key, mydict[key])
How do I get the following output:
Case 1: (by key ascending)
alan 2
bob 1
carl 40
danny 3
Case 2: (by key descending)
danny 3
carl 40
bob 1
alan 2
Case 3: (by value ascending)
bob 1
alan 2
danny 3
carl 40
Case 4: (by value descending)
carl 40
danny 3
alan 2
bob 1