I would like to get the same result which is printed (using the print function in the code below) as function result. If I use a return statement in the loop, then the loop get's broken and I never get to the indexes > 0. How can I store the intermediate result in a (local) variable and eventually return as function result?
l = list("ABCD")
def remel(l, pos):
res = l[:]
del res[pos]
return(res)
def f(l):
if len(l) == 1:
res = l
return(res)
else:
for i in range(len(l)):
res = [l[i]] + f(remel(l, i))
print(res) # store this and pass on how?
return(res)
f(l)