Question: Write a function sort _ demand _ supply ( status ) that takes a dictionary of demands and supplies and returns the information as a

Write a function sort_demand_supply(status) that takes a dictionary of demands and supplies and returns the information as a list of tuples sorted by the value so that locations with greatest demands (the most negative number) are provided first.
Input:
status: a dictionary of demands and supplies. The keys are the location labels (strings) and the values are integers, where a positive value represents supply and a negative value represents demand.
Your function should return a list of tuples, where each tuple is of the form (location, demand_supply), and the list should be sorted in ascending order by their demand_supply (i.e. greatest demand to greatest supply). If two or more locations have the same demand or supply, tie-break by alphanumeric order on their labels.
You may assume:
Inputs are correctly formatted data structures and types
sortdemandsupply(status)
[('L4',-40),('L7',-30),('L2',-5),('3',5),('L5',5),('L6',10),('L8',10),('L1',50)]
Another example:
sortdemandsupply(status)
[('L5',-60),('L3',-50),('L2',-20),('L1',30),('L4',100)]
 Write a function sort_demand_supply(status) that takes a dictionary of demands and

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!