List Deletion and Return

Asked

Viewed 45 times

0

inserir a descrição da imagem aqui

Will be passed as entry list with the current information of a contact, and the phone you want to delete:

• if the phone is in the contact’s phone list, it must be removed.

• if not, no update will be made.

What to do to get the expected output of the "exclusion" function?

def contato(nome,telefone='()',email='()',instagram='()'):

    '''Dados nome, telefone, email e instragram-->str. Retorna uma lista com os dados informados'''
    lista=[nome,[telefone],[email],[instagram]]
    return lista

def exclusão(lista, telefone):

    '''Dado o nome e numero de telefone, retorna a lista sem o numero de telefone informado'''
    P= lista
    B= telefone
    A= P[1]
    if (B in A):
        del(lista[2])
        return lista
    if (B not in A):
        return lista

# Entrada: contato('henrique','22222','nada','@123')
# Valor Esperado: ['henrique', ['22222'], ['nada'], ['@123']]

# Entrada: exclusão('henrique','22222')
# Valor Esperado: ['henrique',['nada'], ['@123']]
# Valor Obtido: 'henrique'
  • Please edit the question to limit it to a specific problem with sufficient detail to identify an appropriate answer.

  • Okay, I’ll put, thank you very much for your help

  • What is the question?

  • Good evening, the serious question= What to do to get the expected output from the "delete" function? Thank you very much for the help.

1 answer

0


Your problem is you reset the variable lista in the function parameter exclusão, replace list by name, and where del(lista[2]) for del(lista[1]) which is the phone index on the list.

Set the variable lista as a variable global so that it can be used for other tasks.

You do not need to place in parentheses the conditions of the formula if, also no need to add another condition if if the phone is not in the list.

Your code goes like this:

def contato(nome,telefone='()',email='()',instagram='()'):
    global lista
    '''Dados nome, telefone, email e instragram-->str. Retorna uma lista com os dados informados'''
    lista=[nome,[telefone],[email],[instagram]]
    return lista

def exclusão(nome, telefone):
    '''Dado o nome e numero de telefone, retorna a lista sem o numero de telefone informado'''
    P = lista
    B = telefone
    A = P[1]
    if B in A:
        del(lista[1])
    return lista

Browser other questions tagged

You are not signed in. Login or sign up in order to post.