How can I sort a dictionary with in the dictionary by the keys of the second dictionary in python?

I have a dictionary as follows:

dict_1 ={'Spain':{'wins':1,'loses':0,'draws':2,'goal_difference':2, 'points':3},'Portugal':{'wins':3,'loses:1,'draws':1,'goal_difference':0,'points':4},'Morocco':{'wins':2,'loses':2,'draws':0,'goal_difference':-2,'points':3}}

I want to sort this dictionary first by the value of points then if the points are equal I want to sort this dictionary by the value wins and lastly if the wins are also equal I want to sort this based on the order of alphabets in keys. So the end result is something like this:

dict_1 ={'Portugal':{'wins':3,'loses:1,'draws':1,'goal_difference':0,'points':4},'Morocco':{'wins':2,'loses':2,'draws':0,'goal_difference':-2,'points':3}},'Spain':{'wins':1,'loses':0,'draws':2,'goal_difference':2, 'points':3}

How can I do this?

I know If I want to sort a dictionary based on the values I can use lambda and sorted:

sorted(dict_1.items(), key=lambda x:x[1])

but I don't know how can I do this when I have dictionary with in the dictionary. I want to do this by lambda and sorted if possible.

Upvotes: 0

Views: 33

Answers (0)

Related Questions