question archive He entire assignment is taking a list of contacts as a csv file in a first_name,last_name,email,phone
Subject:Computer SciencePrice: Bought3
He entire assignment is taking a list of contacts as a csv file in a first_name,last_name,email,phone. This is the function that returns when a user searches by name for a contact and more than one contact exits, to return a list of all the matches vs a single instance of contact.
THE ASSIGNMENT:
find() returns a single instance of Contact. However, there can be multiple instance of Contacts that match the same first/last name. One way to address the problems is to modify find() (and other code necessary) such that it returns a list of Contacts in such case and print them out (the order in the list is not important). Another way is to add a BY_FIRST_AND_LAST_NAME value to the by parameter and an additional menu item to find by first and last name (don't worry about multiple Contacts matching the first and last name in this case). If you choose this, please put a docstring in find() describing your approach.
With either approach, make sure that, if there's only one match, a single instance of Contact is returned as described in the non-extra-credit parts of the assignment. In other words, any extra-credit work must not change how the normal, non-extra-credit code behaves.
this is the function that calls the find(), how do i make it print multiple contacts if multiple contacts exist?
def find_contact(contact_list, by): name = input("Please enter the name to search: ") contact = contact_list.find(name, by) print("n" + str(contact))
the find() function:
def find(self, name, by): """ Find a contact by the given name """ my_lst = [] if by == self.BY_LAST_NAME: for contact in self._contacts: if contact.last_name == name: my_lst.append(contact) else: for contact in self._contacts: if contact.first_name == name: my_lst.append(contact) return my_lst