def search_tool(will_print=False): """If will_print is true will search for and print entries in the phonebook. If false it will return a list with those entries instead.""" search_term = input("Search for: ").lower() is_item_found = False list_out = [] for entry in data.container_phonebook: #Search for each dictionary in the list. for key in entry: #Search for each key in the dictionary. if entry[key].lower( ) == search_term: #Search each value in the dictionary. if will_print == True: print("{first_name} {last_name}: {number}".format(**entry) ) #** is an operator that unpacks a dictionary. is_item_found = True else: list_out.append(entry) if ("{first_name} {last_name}".format(**entry)).lower() == search_term: print("{first_name} {last_name}: {number}".format( **entry)) #** is an operator that unpacks a dictionary. is_item_found = True if is_item_found == False: print("No Entries Found") await_input() return list_out
def change_phone_number(index): modified_entry_number = input("Enter the new number (555-555-5555): ") print(f"Is {modified_entry_number} correct? Y/N") confirmation = input(">> ") if menu.get_confirmation(confirmation) == True: #TODO: Add exception handler. data.container_phonebook[index]["number"] = modified_entry_number print("Entry Saved") menu.await_input()
def delete_entry(phonebook_index, msg): print(msg) print("Would you like to delete this entry? Y/N") confirmation = input(">> ") if menu.get_confirmation(confirmation) == True: data.container_phonebook.pop(phonebook_index) print("Entry Deleted.") menu.await_input()
def create_new_entry(): print("Creating new entry.") new_entry_first_name = input("First Name: ") new_entry_last_name = input("Last Name: ") new_entry_number = input("Phone Number (555-555-5555): ") print("Is this correct? Y/N") print(f"Name: {new_entry_first_name} {new_entry_last_name}") print(f"Number {new_entry_number}") confirmation = input(">> ") if menu.get_confirmation(confirmation) == True: data.container_phonebook.append({ "first_name": new_entry_first_name, "last_name": new_entry_last_name, "number": new_entry_number }) else: print("Operation canceled") menu.await_input()
def list_all(): """Lists all Entries. """ for entry in data.container_phonebook: print("{first_name} {last_name}: {number}".format(**entry)) await_input()