Skip to content
Advertisement

Iterate through nested dictionary values and return an ordered list based on dict’s values

I have a nested dictionary titled ‘transportation_costs’ that contains the transportation costs associated with every facility-customer combination. I need to iterate through each customer (key2) in the dictionary and generate five ordered lists (one for each customer) that contains the facilities ranked from cheapest to most expensive for a given customer based on the value in the nested dictionary.

*** When I say “cheapest”, I mean it has a lower transportation cost.

JavaScript

I need the final ouput to be something like this:

JavaScript

Advertisement

Answer

Try:

JavaScript

Prints:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement