Perfumes ======== .. py:module:: perfumes The company SMELLS S.A. produces several perfumes and saves the data in a list of sublists where each sublist corresponds to a perfume and has the following data: perfume name (string), perfume type (a string that can be ``'PARFUM', 'EAU_PARFUM', 'EAU_TOILETTE'`` or ``'EAU_COLOGNE'``), net content in ml (int) and price in euros (float). Save the following functions into the same file named ``perfumes.py``. .. py:function:: perfumes1(lperfumes) Given a perfumes list as described, this function returns a dictionary where the key is a net content and the value is a list with those perfume names that have this net content. Perfume names in these lists are in the same order as in the given list. .. literalinclude:: test-perfumes1.txt :language: python :lines: 3- .. Note:: More tests are provided in file :download:`test-perfumes1.txt`. .. py:function:: perfumes2(lperfumes) Given a perfumes list as described, this function returns a dictionary where the key is a perfume type and the value is a list of sublists of perfumes of this type. Each sublist has two elements: the perfume name and its price. Perfume names in these lists are in the same order as in the given list. .. literalinclude:: test-perfumes2.txt :language: python :lines: 3- .. Note:: More tests are provided in file :download:`test-perfumes2.txt`. .. py:function:: buy1(perfumes, euros) Given a dictionary as the one returned by function ``creaperfumes2``, a perfume type and an amount of euros, this function returns ``True`` if there is a perfume in the given dictionary of the given type that can be bought with the given amount and ``False`` otherwise. .. literalinclude:: test-buy1.txt :language: python :lines: 3- .. Note:: More tests are provided in file :download:`test-buy1.txt`. .. py:function:: buy2 Given a dictionary as the one returned by function ``creaperfumes2`` and an amount of euros, this function returns a list with those perfume names that have a price less than or equal to the given amount. This list must be ordered lexicographically. .. literalinclude:: test-buy2.txt :language: python :lines: 3- .. Note:: More tests are provided in file :download:`test-buy2.txt`. .. rubric:: Solution A solution of these functions is provided in file :download:`perfumes.py `.