Bus4 ==== Consider a dictionary (:class:`dict`) with information about the passengers of an interurban bus. Let's call it the *passengers dictionary* (:class:`psgD`) where the *keys* are passenger identifiers, each composed of a 2-component :class:`tuple` with following passenger's info: - the id number (:class:`str`) - the name (:class:`str`) composed of two words separated by ``' '``. The *value* associated to each passenger is a 4-component :class:`list` with information about the passenger's trip: - the town of origin (:class:`srt`) - the town of destination or *stop* (:class:`srt`) - the row and seat assigned to that passenger (:class:`int`) For example: .. literalinclude:: Move_Row_psgD.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:`bus4` (file :file:`bus4.py`). The tentative *weight* for each problem is 25%, 50% and 25% respectively. .. 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. ------------------------------------------------------------------------------------------------ The first function is: .. py:function:: Move_Row_psgD(psgD, dest, delta) such that **given** - *psgD* a :class:`dict` as described above - *dest* a :class:`str` with a stop - *delta* an :class:`int` the *displacement* **updates** *psgD* by changing all the rows for passengers with the *dest* destination and moving them *delta* rows in the bus. This displacement can be positive or negative but moving is always calculated by adding it to the current row. For example, given the passenger dict above: .. literalinclude:: Move_Row_psgD.test :language: pycon :start-after: --out-ini :end-before: --out-fi Doctests are available in the :download:`Move_Row_psgD.test` file. ------------------------------------------------------------------------------------------------ The second function is intended to construct a new dictionary for the bus driver that lists the passengers that are suposed to get in the bus at each pickup point. To that purpose, you are asked to deliver the following function: .. py:function:: Construct_pickupD(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 in the bus. #. The value associated to each key is a :class:`list` with the passengers supposed to get in the bus at that stop. Each passenger is represented by a 4-place :class:`tuple` with: **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 in the bus. #. The value associated to each key is a :class:`list` with the passengers supposed to get in the bus at that stop. Each passenger is represented by a 4-place :class:`tuple` with: - the destination (:class:`str`) - the passenger name (:class:`str`) - the row and seat numbers (:class:`int`) The input :class:`dict` should **not** be modified. For example: .. literalinclude:: Construct_pickupD.test :language: pycon :start-after: --in-ini :end-before: --out-fi Doctests are available in the :download:`Construct_pickupD.test` file. ------------------------------------------------------------------------------------------------ The third function is intended to order all the lists in the values of the :class:`dict` produced by the previous function: .. py:function:: Sort_pickupD(pickupD) such that **given** *pickupD* a :class:`dict` as described for the output of the previous function **updates** *pickupD* by **ordering** the passengers in the lists for each pickup point according to the following criteria (in this order of priority): #. The destination, in alphabetic order. #. The row number, in descending order. #. The passenger name, in alphabetic order. For example: .. literalinclude:: Sort_pickupD.test :language: pycon :start-after: --ini :end-before: --fi Doctests are available in the :download:`Sort_pickupD.test` file.