2
I am developing a function that takes 3 parameters fctn(Function, list, element) and that it has to return a list with the intermediate states of the accumulator, as in the example below:
>>> fctn(lambda acc, x: acc + x, [1, 2, 3, 4], 0)
[0, 1, 3, 5,7]
My code:
def fctn(function, list, element):
acc = elem
for x in list:
list = map(lambda acc: lambda x: acc + x, l)
return list
But don’t give back what I want...
The question is a little confused, try to demonstrate through a common function (without lambda) or even through pseudocode or table test.
– Sidon
Dude... I get it. It’s pretty much the same question I answered a few hours ago. I refactored the code to answer your question.
– Sidon
please post code with correct indentation
– jsbueno
@py_9, According to your text, to be a accumulator with
lambda acc, x: acc + x
should not give the list of accumulated sums[0, 1, 3, 6, 10]
?– JJoao