Contact book ============ .. py:module:: contact_book Write the next functions and save them in file :file:`contact_book.py`: .. py:function:: make_contact_book(ldata) Given a list of lists, ``ldata``, where each sublist contains two strings that represent a name and a phone, return a dictionary whose keys are a string with the name, and the values a string with the phone number. Suppose there are no names repeated at ``ldata``. For example: .. literalinclude:: test-make_contact_book.txt :language: python :lines: 3- .. note:: More tests are provided in file :download:`test-make_contact_book.txt `. .. py:function:: count_prefixs(contact_book, prefix) Given a dictionary, ``contact_book``, as the one returned by the function :py:func:`make_contact_book` and a telephone prefix (string), returns how many numbers of the contact book dictionary start with this prefix. For example, .. literalinclude:: test-count_prefix.txt :language: python :lines: 3- .. note:: More tests are provided in file :download:`test-count_prefix.txt `. .. py:function:: have_prefix(contact_book, prefix) Given a dictionary, ``contact_book``, as the one returned by the function :py:func:`make_contact_book` and a phone prefix (string), return a Boolean indicating if any phone of the contact book starts with the indicated prefix. For example, .. literalinclude:: test-have_prefix.txt :language: python :lines: 3- .. note:: More tests are provided in file :download:`test-have_prefix.txt `. .. py:function:: names_prefix(contact_book, prefix) Given a dictionary, ``contact_book``, as the one returned by the function :py:func:`make_contact_book` and a telephone prefix (string), returns a list with the names that have a phone with this prefix, sorted alphabetically. For example, .. literalinclude:: test-names_prefix.txt :language: python :lines: 3- .. note:: More tests are provided in file :download:`test-names_prefix.txt `. .. py:function:: make_contact_book_reps(ldata) It does the same thing as function :py:func:`make_contact_book` but in this case in list ``ldata`` names may appear more than once. Returns a dictionary whose keys are the names, and each associated value is a list of strings with all telephone numbers that correspond to the name. The order of the phones of each name will be the same as the order they appear on the given list. For example, .. literalinclude:: test-make_contact_book_reps.txt :language: python :lines: 3- .. note:: More tests are provided in file :download:`test-make_contact_book_reps.txt `. .. rubric:: Solution A solution of these functions is provided in file :download:`contact_book.py `.