Sorting Town Temperatures ========================= Let's consider a list with information regarding the weather temperatures measured in a number of towns. The information for each town is represented in a 4-component :class:`tuple` with the following fields: - an identification number (:class:`int`) - the town name (:class:`str`) - a list of temperatures (:class:`list` of :class:`float`) - the updated flag (:class:`bool`): ``True`` is the info is up to date and ``False`` otherwise. For example: .. literalinclude:: sort_townL.test :language: pycon :start-after: --ini :end-before: --fi An auxiliar function called `print_townL` is provided to you in the :download:`town_tools.py` file. This function is not a code to be used in your implementation but rather a tool that can be useful when you are testing your results to display the data in a towns list. .. literalinclude:: town_tools.py :language: python You are required to deliver the following functions in the module :mod:`sort_town_temp` (file :file:`sort_town_temp.py`). ------------------------------------------------------------------------------------------------ The function: .. py:function:: sort_townL(tL) such that **given** ``tL``, a :class:`list` as described above **returns** a new :class:`list` with exactly the same information but reordered according to the following criteria (in this order of priority): #. The ones that are not updated go before the ones that are. #. The name in alfabetic order. For example: .. literalinclude:: sort_townL.test :language: pycon :start-after: --ini-out :end-before: --fi-out Doctests are available in the :download:`sort_townL.test` file. .. warning:: The input list **must** remain intact. ------------------------------------------------------------------------------------------------ The function: .. py:function:: sort_max_townL(tL) such that **given** ``tL``, a :class:`list` as described above **returns** a new :class:`list` with exactly the same information but reordered according to the following criteria (in this order of priority): #. The ones that are not updated go before the ones that are. #. The **maximum** temperature registered in the town, in descending order. #. The name in alfabetic order. For example: .. literalinclude:: sort_max_townL.test :language: pycon :start-after: --ini-out :end-before: --fi-out .. warning:: This input list **must not** be modified by the function. Doctests are available in the :download:`sort_max_townL.test` file. ------------------------------------------------------------------------------------------------ The function: .. py:function:: sort_tempL(tL) such that **given** ``tL``, a :class:`list` of town temperatures as described above **sorts** all the lists of temperatures within *tL* in ascending order. For example, see the effects of this function over the input list above: .. literalinclude:: sort_tempL.test :language: pycon :start-after: --ini-out :end-before: --fi-out .. warning:: Notice that all temperatures in ``tL`` are now increasingly ordered but the rest of the information remain intact. In particular, all towns remain in their same position in the input list. Doctests are available in the :download:`sort_tempL.test` file. ------------------------------------------------------------------------------------------------ The function: .. py:function:: sort_avg_townL(tL) such that **given** ``tL``, a :class:`list` as described above **returns** a new :class:`list` with exactly the same information but reordered according to the following criteria (in this order of priority): #. The average temperature in descending order. #. The name without the ``'Vila'`` prefix in alphabetic order. For example: .. literalinclude:: sort_avg_townL.test :language: pycon :start-after: --ini-out :end-before: --fi-out .. warning:: This input list **must not** be modified by the function. Doctests are available in the :download:`sort_avg_townL.test` file.