Sorting a dictionary by key in Python
scores = {'Naveen' : 5, 'Arthi' : 2, 'Subash' : 4} for key in sorted(scores): print("%s: %s" % (key, scores[key]))
dict = {2: 3, 1: 89, 4: 5, 3: 0} od = sorted(dict.items()) print(od)
scores = {'Naveen' : 5, 'Arthi' : 2, 'Subash' : 4} for key in sorted(scores): print("%s: %s" % (key, scores[key]))
dict = {2: 3, 1: 89, 4: 5, 3: 0} od = sorted(dict.items()) print(od)