-2
Implement a recursive file_recursive function it receives a list and a number and returns the list, except every time the number appears
For example
filtro_recursivo([0,1,2,1,4],1)
returns[0,2,4]
For examplefiltro_recursivo([0,1,2,1,4],4)
returns[0,1,2,1]
For examplefiltro_recursivo([0,1,2,1,4],5)
returns[0,1,2,1,4]
For examplefiltro_recursivo([],5)
returns[]
The first test takes the "simple case": lists with 0 or 1 element After passing it, implement recursion using the two ideas below
filtro_recursivo([5, resto],5) = filtro_recursivo(resto);
filtro_recursivo([8, resto],5) = [8]+filtro_recursivo(resto);
I implemented so only that did not pass the test
def filtro_recursivo(lista, numero):
for i in range(0, len(lista)):
if lista [i] == numero:
lista.pop(i)
return lista
What is this identifier
resto
?– Augusto Vasques
is the rest give recursion .
– Romulo Silva Souza Santos
Rest of the recursion? Doesn’t make any sense
– Augusto Vasques
How can you get the rest of an operation that has not yet occurred?
– Augusto Vasques
If one of the answers below solved your problem and there was no doubt left, choose the one you liked the most and mark it as correct/accepted by clicking on the " " that is next to it, which also marks your question as solved. If you still have any questions or would like further clarification, feel free to comment.
– Augusto Vasques