Advertisement
Sichanov

sort

Nov 5th, 2021
1,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. collection = {'Arnoldii': {'rarity': 4, 'rating': [], 'avg_rating': 0.0},
  2.               'Woodii': {'rarity': 5, 'rating': [10, 5], 'avg_rating': 7.5},
  3.               'Welwitschia': {'rarity': 2, 'rating': [7], 'avg_rating': 7.0}}
  4.  
  5. sorted_colletion = sorted(collection.items(), key=lambda kvp: (kvp[1]['rarity'], kvp[1]['avg_rating']))
  6. print(sorted_colletion)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement