I am new in Python I am trying to sort I saw some posts on stackoverflow but i was not able to get my headaround the problem
graph = {
'A': [('B', 9), ('C', 7)],
'B': [('A', 5), ('D', 8), ('E', 1)],
'E': [('B', 1), ('D', 2)],
'D': [('B', 8), ('E', 2), ('F', 7), ('C', 2), ('I', 5)],
'F': [('D', 7)],
'I': [('D', 5), ('G', 14)],
'G': [('I', 14), ('C', 13)],
'C': [('A', 7), ('D', 2), ('G', 13)]}
for key, value in sorted(graph.items(), key=lambda item: (item[1], item[0])):
print ("%s: %s" % (key, value))
I want to sort this dictionary by value of each element For Example First item becomes 'A': [('C', '7'), ('B', 9)], 'B': [('E', 1),('A', 5), ('D', 8)], and so on
How can i do that in python