I have been trying to figure out how to return the key which has the nth biggest value in a nested dictionary. What causes problems for me is if there's some missing values like
my_dict = {'0': {'name': 'A', 'price': 50}, '1': {'name': 'B', 'price': 20}, '2': {'name': 'C'}, '3': {'name': 'D', 'price': 10}}
If every price existed, I could use code such as this to get the correct key:
sorted_list = sorted(my_dict.items(), key=lambda item: item[1]['price'])
print(sorted_list[-number_im_using_to_find][1]['name'])
How to account for missing values in an efficient way?