For one of my rev questions I am trying to write a function that updates a list of tuples whenever a user decides to add a new contact. This has to be done by removing a tuple if the new contact name already exists in the list and appending the new contact info into the list.
code so far
code so far
def update_contact(list_of_tuples, search_name, new_phone):
if search_name in list(sum(list_of_tuples, ())):
x = list_of_tuples.index(search_name)
list_of_tuples.remove(x)
new_entry = (search_name, new_phone)
list_of_tuples.append(new_entry)
print(search_name + "'s phone number has been updated.")
else:
print(search_name, "is NOT found.")Expected output:data = [('Jill', '5239980'), ('Bob', '4562345'), ('Jenny', '2541273')]
update_contact(data, 'Bob', '1111111')
update_contact(data, 'Daniel', '2222222')
Bob's phone number has been updated.
Daniel is NOT found.
Jill's phone number is 5239980
Jenny's phone number is 2541273
Bob's phone number is 1111111
There are 3 contacts in the list.Error:x = list_of_tuples.index(search_name)
ValueError: 'Bob' is not in listI'm confused because Bob is in the list?
