Bikes ===== Let's consider a given dictionary where the key is an :class:`int` with a person's *ID number* and the value is a :class:`str` with the name of her/his city of residence. For example: .. literalinclude:: bikeD_gen.test :language: python3 :start-after: --ini1 :end-before: --fi1 In this context, you are required to deliver the following functions in the module :mod:`bikes` (file :file:`bikes.py`): ------------------------------------------------------------------------------------------------ The first function is: .. py:function:: bikeD_gen(id_city_D, id_bike_D) such that **given** - *id_city_D*, is a :class:`dict` as described above - *id_bike_D*, is a :class:`dict` where the key is a :class:`int` with a person's *ID number* and the corresponding value is a :class:`str` with the brand of his/her **motor bike**. **returns** a :class:`dict` with the inverted info of *id_bike_D* but only with the persons included in *id_city_D*. Specifically the keys of the new dict are bike brands appearing as values in *id_bike_D* and the value corresponding to each key is a :class:`list` of Id numbers, the ones that who appear in *id_city_D* and own a bike of that brand according to *id_bike_D*. The order of these lists is the same as in the input dictionary. For example: .. literalinclude:: bikeD_gen.test :language: python3 :start-after: --ini2 :end-before: --fi2 Observe that the id ``77888999`` is not listed in ``'Ducati``'s value because it is not a key in ``id_city_d``. Doctests are available in the :download:`bikeD_gen.test` file. ------------------------------------------------------------------------------------------------ Now let's consider the case where a person can own more that one bike. Hence we have the dictionary *id_bikes_D* where the key is a :class:`int` with a person's *ID number* and the associated value is a :class:`list` of :class:`str` with the brands of the *motor bikes* owned by that person. For example: .. literalinclude:: cityD_gen.test :language: python3 :start-after: --ini1 :end-before: --fi1 The second function is: .. py:function:: cityD_gen(id_city_D, id_bikes_D, brd) such that **given** - *id_city_D*, is a :class:`dict` as described at the beginning - *id_bikes_D*, is a :class:`dict` as described above - *brd*, a :class:`str` with a motor bike brand name **returns** a :class:`dict` with all *Idn*s in *id_city_D* that own a motorbike whose brand is *brd*. The key is a :class:`str` with a city of residence according to *id_city_D* and the associated value is an **aphabetically ordered** :class:`list` of those person's Idn (:class:`int`). The owners of a bike of brand *brd* in *id_bikes_D* that do not appear in *id_city_D* must be listed under the ``'Unknown'`` key. Notice that the cities where there is no bike owner of this brand are not included in the dictionary's keys. For instance, observe the following example: in the first call, the Id ``77888999`` is listed under the ``'Unknown'`` since it belongs to somebody who owns a Ducati but is not included in *id_city_D*. Furthermore, in the second call, all Ducati owners are listed under the ``'Unknown'`` key since the *id_city_D* provided is empty. For example: .. literalinclude:: cityD_gen.test :language: python3 :start-after: --ini2 :end-before: --fi2 Observe that the second example, all ``'Ducati`` owners are listed in the ``Unknown`` key since the is the is empty. Doctests are available in the :download:`cityD_gen.test` file.