0
def dobra(lista, l_dobro = []):
if lista == []:
return
else:
dobro = lista[0] * 2
l_dobro.append(dobro)
dobra(lista[1:], l_dobro)
lista = l_dobro
return lista
I’m trying to do this function using recursion, and if I call it more than once, it replicates the list that was passed as parameter at the previous time, the l_double in the case. How can I clear her for the next instance?
try to use
l_dobro.clear()
– WhoisMatt
Hello Bruno, welcome back! It is easier to help you if you tell us where/how you want to use this "fold" function, maybe there are other easier ways to achieve the same result. ;-)
– Cleyton