Bus === Consider a dictionary (:class:`dict`) with information about the passengers of an interurban bus. Let's call it a passengers dictionary (:class:`psgD`). The *keys* in :class:`psgD` are person identifiers, each composed of a 2-component :class:`tuple` with a number (:class:`int`) and one capital letter (:class:`str`). The *values* in :class:`psgD` are 4-component :class:`tuple` with: - the passenger's name (:class:`srt`) - the row and seat where his/her is supposed to seat (:class:`int`) - the passenger's destination or *stop* (:class:`srt`) For example: .. literalinclude:: gen_stops_D.test :language: pycon :start-after: --in-ini :end-before: --in-fi You are required to implement the following functions and deliver **all of them** in the same module :mod:`bus` (file :file:`bus.py`). The tentative **weight** for each problem is 60%, 10%, 20% and 10% respectively, although the weight of the former function could be increased. .. warning:: Do not leave pieces of code that are wither incomplete or contain syntax errors in the file to deliver since that would result in a 0.0 grade for all the functions. ------------------------------------------------------------------------------------------------ First we need to generate a new dictionary for the bus driver indicating the passengers that are suposed to get off the bus at each stop. To that purpose, you are asked to deliver the following function: .. py:function:: gen_stops_D(psgD) such that **given** *psgD* a passenger's :class:`dict` as described above **returns** a new :class:`dict` where: #. The keys are the stops (:class:`str`) where at least one passenger is supposed to get off. destination. #. The value associated to each key is a :class:`list` with the names of the passengers supposed to get off at that stop. The input :class:`dict` should **not** be modified. For example: .. literalinclude:: gen_stops_D.test :language: pycon :start-after: --in-ini :end-before: --out-fi Doctests are available in the :download:`gen_stops_D.test` file. ------------------------------------------------------------------------------------------------ Second, we want the lists in all values of the :class:`dict` produced by the previous function to be aphabetically ordered: .. py:function:: sort_stops_D(stpD) such that **given** *stpD* a :class:`dict` as described for the output of the previous function **updates** *stpD* by **alphabetically ordering** the names in the lists in its values and nothing else. For example: .. literalinclude:: sort_stops_D.test :language: pycon :start-after: --ini :end-before: --fi Doctests are available in the :download:`sort_stops_D.test` file. ------------------------------------------------------------------------------------------------ Third, we need a function to support the change of the destination of a particular passenger given the passenger's name: .. py:function:: upd_dest_D(psgD, name, newdest) such that **given** *psgD* a :class:`dict` as described above **updates** *psgD* by changing the destination of the passenger named *name*. If there is no passenger with that name in *psgD* then it is not modified. **returns** the passenger identifier (:class:`tuple`) and his/her new destination (:class:`str`). If there is no passenger with that name in *psgD* then the empty tuple is returned as the passenger's identifier. For example: .. literalinclude:: upd_dest_D.test :language: pycon :start-after: --ini :end-before: --fi Doctests are available in the :download:`upd_dest_D.test` file. ------------------------------------------------------------------------------------------------ Fourth, we wish to *generate* and *sort* a :class:`list` with the information from a given passengers :class:`dict` as described above at the beginning above. To that purpose you have to implement the following function: .. py:function:: sort_pass_L(psgD) such that **given** *psgD* a :class:`dict` as described above **returns** a :class:`dict` such that - It contains exactly the information of the values of *psgD*, hence a :class:`list` of :class:`tuple`. - The tuples are ordered according to the following criteria from higher to lower priority: #. The name of the distination in **alphabetical** order. #. The number of *row* in **decreasing** order. #. The name, **alphabetically**. For example: .. literalinclude:: sort_pass_L.test :language: pycon :start-after: --ini :end-before: --fi Doctests are available in the :download:`sort_pass_L.test` file.