Tank Sorting¶
Again in the context of the water tanks from the previous problem, you are required to deliver the following sorting functions in the module tank_sorting (file tank_sorting.py).
The first function is:
- tank_sort_1(tL)¶
such that
given tL a
listof of water tank info as described abovereturns a copy of tL but where that the tanks are ordered by placing first the tanks with more water contributions. In case of a tie the order in Lt is maintained.
For example:
>>> tanksL = [ ... ['Carmel', 20, [2, 3, 4, 1, 5, 1]], ... ['Nou_Barris', 10, [1, 2, 1, 5, 10]], ... ['Sant_Pere_Martir', 15, [2, 4, 8, 4, 2, 5, 7, 4]], ... ] >>> newtanksL = tank_sort_1(tanksL) >>> newtanksL == [ ... ['Sant_Pere_Martir', 15, [2, 4, 8, 4, 2, 5, 7, 4]], ... ['Carmel', 20, [2, 3, 4, 1, 5, 1]], ... ['Nou_Barris', 10, [1, 2, 1, 5, 10]], ... ] True
Doctests are available in the tank_sort_1.test file.
The second function is:
- tank_sort_2(tL)¶
such that
given tL a
listof water tank info as described aboverearranges tL by placing first the tanks with higher capacity. The tanks with the same capacity must be alphabetically ordered.
For example:
>>> tanksL = [ ... ['Carmel', 20, [2, 3, 4, 1, 5, 1]], ... ['Nou_Barris', 10, [1, 2, 1, 5, 10]], ... ['Sant_Pere_Martir', 15, [2, 4, 8, 4, 2, 5, 7, 4]], ... ['N3', 10, [2, 3, 4, 1, 5, 1]], ... ['N2', 10, [1, 2, 1, 5, 10]], ... ['Sant_Antoni', 15, [2, 4, 8, 4, 2, 5, 7, 4]], ... ] >>> tank_sort_2(tanksL) >>> tanksL == [ ... ['Carmel', 20, [2, 3, 4, 1, 5, 1]], ... ['Sant_Antoni', 15, [2, 4, 8, 4, 2, 5, 7, 4]], ... ['Sant_Pere_Martir', 15, [2, 4, 8, 4, 2, 5, 7, 4]], ... ['N2', 10, [1, 2, 1, 5, 10]], ... ['N3', 10, [2, 3, 4, 1, 5, 1]], ... ['Nou_Barris', 10, [1, 2, 1, 5, 10]], ... ] True
Doctests are available in the tank_sort_2.test file.