1
Good afternoon, this week my teacher passed me the question of scheduling a phone book. I did with dictionary but he had me redo with lists.
There’s a part where I have to remove a contact from the phone book and his number. But I don’t know how to remove the name that is an unknown index. If I can find the index of the name, it is easy to remove the index of the number. But how do I find the name index?
agenda = []
while True:
print("=================")
print("Agenda INTIN")
print("=================")
print("Menu de opções:")
print("1 - Cadastrar novo contato")
print("2 - Buscar contato")
print("3 - Alterar contato")
print("4 - Excluir contato")
print("5 - Listar todos os contatos")
print("6 - Sair")
print("----------------------------")
opcao = int(input("Digite uma opcao: "))
if(opcao == 4):
busca = input("Digite o nome do contato que deseja excluir: ")
if(busca in lista == True):
agenda.remove("busca")
agenda.remove(
print("Contato excluido com sucesso")
else:
print("ERROR")
print("Contato inexistente")
print("----------------------------")
Welcome, try to use one
agenda.index(busca)
should return the index and then just remove– Luiz Augusto
index returns in a print? how does it return?? ;-; (sorry, to no 1° computer year and I’m new)
– Mariana Freitinhas
Remember that we are all students! Ileia this, will help you Using the index() method of the Python list in a list of tuples or objects?
– Luiz Augusto
Thank you! That was very kind of you ^^
– Mariana Freitinhas