.. py:module:: trucks Trucks ====== A transport company wants to distribute the cargo of certain products in their trucks. It has a nested list where each sublist corresponds to a product and consists of two elements: the product code (:class:`str`) and its quantity in kg (:class:`int`). Write the **modifier** function :py:func:`assign_truck` that from a list like the one mentioned, the code of a truck (:class:`str`) and the amount that it can carry, in Kg (:class:`int`), **modifies** the list of products so that the sublists with the products assigned to the truck have a third item corresponding to the code of the truck. The allocation of the products to the truck is done according to the following criteria: - the order of product allocation is the same order in which products appear in the list, - a product must be assigned completely: the corresponding amount can not be split, and - we must allocate as many products as they fit in the truck. Save this function into file :file:`trucks.py`. Example: .. literalinclude:: test-assign_truck.txt :language: python3 :lines: 3-6 In this case, product ``'LJ8'`` cannot be assigned to the truck because the associated amount, ``78``, would cause the truck's capacity to be exceeded, ``250``. Conversely, product ``'TF'`` can be assigned because the associated quantity ``14``, added to the quantity of previously assigned products, does not exceed the capacity of the truck. More tests are provided in file: :download:`test-assign_truck.txt`. .. rubric:: Solution A solution is provided in file :download:`trucks.py`