Bus2 ==== Consider a dictionary (:class:`dict`) with information about the passengers of an interurban bus. Let's call it a passengers dictionary (or :class:`psgD` for short). 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_stop_seats_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:`bus2` (file :file:`bus2.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_stop_seats_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. #. The value associated to each stop is a :class:`list` of the row and seat (:class:`tuple`) of the passengers supposed to get off at that stop. The seats will preserve the order coming from the `psgG` traversal order (so they do not need to be re-ordered right now). The input :class:`dict` should **not** be modified. For example: .. literalinclude:: gen_stop_seats_D.test :language: pycon :start-after: --in-ini :end-before: --out-fi Doctests are available in the :download:`gen_stop_seats_D.test` file. ------------------------------------------------------------------------------------------------ Second, we want the lists of seats in the :class:`dict` output of the previous function to be increasingly ordered: .. py:function:: sort_stop_seats_D(stpD) such that **given** *stpD* a :class:`dict` as described for the output of the previous function **updates** *stpD* by ordering the lists of seats in the values of all keys as follows: increasingly by the row, and, the seats in the same row also increasingly by the seat. Nothing else should be changed. For example: .. literalinclude:: sort_stop_seats_D.test :language: pycon :start-after: --ini :end-before: --fi Doctests are available in the :download:`sort_stop_seats_D.test` file. ------------------------------------------------------------------------------------------------ Third, we need a function to support the change of the seat of a particular passenger: .. py:function:: move_passenger(psgD, name, new_row, new_seat) such that **given** *psgD* a :class:`dict` as described above does 2 things: **updates** *psgD* by changing the row and seat of the passenger named *name* to *new_row*, *new_seat* respectively. If there is no passenger with that name in *psgD* then no modification is done. **returns** the passenger identifier (:class:`tuple` of :class:`int` and :class:`str`) and his/her new row and seat (:class:`tuple` of :class:`int`). If there is no passenger with that name in *psgD* then the empty tuple is returned instead of the passenger's identifier, together with the intended new row and seat. For example: .. literalinclude:: move_passenger.test :language: pycon :start-after: --ini :end-before: --fi Doctests are available in the :download:`move_passenger.test` file. ------------------------------------------------------------------------------------------------ Fourth, we wish to *generate* and *sort* a :class:`list` from a given passengers :class:`dict` as described above at the beginning. To that purpose you have to implement the following function: .. py:function:: sort_pass_L_2(psgD) such that **given** *psgD* a :class:`dict` as described above **returns** a :class:`list` such that - It contains exactly all the information of *psgD* in the following way: for each entry in *psgD* there is a single :class:`tuple` with the information from both the key and the value of that entry. - The tuples are ordered according to the following criteria (ordered from higher to lower priority): #. The name of the distination in **alphabetical** order. #. The number of *row* in **decreasing** order. #. The passanger's identifier number, **increasingly**. For example: .. literalinclude:: sort_pass_L_2.test :language: pycon :start-after: --ini :end-before: --fi Doctests are available in the :download:`sort_pass_L_2.test` file.