Failures (4 points) =================== Failures in the tram network of a city are stored in a nested :class:`list`. Each item of this list is another list with the following 6 items: the tram identifier (:class:`str`), the line identifier (:class:`str`), the failure code (:class:`str`), the type of failure (:class:`str`) that can be ``'elec'`` or ``'mec'``, the time spent in arriving at the place with the tram failure (:class:`int`), and the time spent in repairing the failure (:class:`int`). Both times are given in minutes. Solve the **two** following exercises and save each function in the corresponding file: 1. (**2 points**) Write function :py:func:`failures` that takes a nested list as that described, and returns 2 dictionaries (:class:`dict`): the first one for electrical failures (type ``'elec'``) and the second one for mechanical failures (type ``'mec'``). In both dictionaries the key is the line identifier (:class:`str`) and the value is a :class:`list` of tuples (:class:`tuple`); each tuple corresponds to a failure and has three items: the total time (in minutes) needed to repair the failure (:class:`int`), the tram identifier (:class:`str`), and the failure code (:class:`str`). The total time is the sum of the arriving time plus the repairing time. Tuples in all the lists of both dictionaries must be sorted by total time. Save this function in file ``failures.py``. Example: .. literalinclude:: test-failures.txt :language: python :lines: 3-18 .. note:: Tests are provided in file :download:`test-failures.txt`. 2. (**2 points**) More data on failures is stored in a dictionary (:class:`dict`) in which the key is the failure code (:class:`str`) and the value is a :class:`tuple` with 2 items: the time when the failure was notified, and the name of the worker (:class:`str`). The notification time is represented with a :class:`tuple` of the form ``(hour, minute)``, where ``hour`` and ``minute`` are two positive integers and ``hour < 24`` and ``minute < 60``. Write the **modifier** function :py:func:`time_failure` that takes a nested list as that described in the introduction, and a dictionary as that described in the previous paragraph. This function **modifies** the given list in such a way that each sublist will have a new format with 3 items: the tram identifier (:class:`str`), the worker name (:class:`str`), and the ending time of the repair. This ending time is computed by adding both the arriving and the repairing time to the notification time and it is represented in the same format as the notification time. The given data is such that all these ending times will fall in the same day, i.e., ``hour < 24`` (you don't need to check it). Save this function in file ``time_failure.py``. Example: .. literalinclude:: test-time_failure.txt :language: python :lines: 3-26 .. note:: Tests are provided in file :download:`test-time_failure.txt`.