Jun-20-2019, 02:14 PM
Thank you guys for the advices, I have now completed my task, by adding another argument to the recursive function, and now I send full list instead of a slice to the function. I have also simplified the iteration version of the function.
noisefloor,
I wanted to achieve what was made by iter_45 function, like you mentioned, but opposite way:
Input:
The supplement at the end of my variable names is just my ID required by the teacher, it doesn't mean anything :)
I know it could be simplier and/or better, but now it looks like this:
noisefloor,
I wanted to achieve what was made by iter_45 function, like you mentioned, but opposite way:
Input:
[1, 2, 3, 4]
, output [10, 6, 3]
.The supplement at the end of my variable names is just my ID required by the teacher, it doesn't mean anything :)
I know it could be simplier and/or better, but now it looks like this:
A=[1,0,2,0,0,3,1,3,2,1] def iter_45(lista): nowa_lista_i = [] for i in range (0, len(lista)): nowa_lista_i.append(sum(lista[i:])) return nowa_lista_i nowa_lista = [] i = 0 def req_45(lista, i): global nowa_lista if i == len(lista): return nowa_lista else: nowa_lista = nowa_lista + [sum(lista[i:])] i += 1 return req_45(lista, i) print('iteracyjnie:\n') print(iter_45(A)) print('\nrekurencyjnie:\n') print(req_45(A,0))Thanks again for help :)