recursive cumulative sums
<p>I need to write a program that compute cumulative sums from a list of numbers with def but ONLY with recursion.
I did it, but now I need to write the same program without using the method <code>sum</code>, but no success so far.
Any idea?</p>

<p>my code:</p>

<pre><code>def rec_cumsum(numbers):
        ''' Input: numbers - a list of numbers,
                Output: a list of cumulative sums of the numbers'''
        if len(numbers)==0: return numbers

        return rec_cumsum(numbers[:-1])+ [sum(numbers)]
</code></pre>

<p>input:</p>

<p>1    <code>[1,2,3]</code></p>

<p>2     <code>[2, 2, 2, 3]</code></p>

<p>output:</p>

<p>1    <code>[1,3,6]</code></p>

<p>2    <code>[2, 4, 6, 9]</code></p>

<hr>

<p>my code without <code>sum</code>:</p>

<pre><code>def rec_cumsum(numbers):
        ''' Input: numbers - a list of numbers,
                Output: a list of cumulative sums of the numbers'''
        if len(numbers) == 0: return numbers
        my_list=[]
        rec_cumsum(my_list + numbers)
        my_list[0]=numbers[0]
        rec_cumsum(my_list)
        temp_sum=my_list[0]+numbers[-1]
        my_list[0]=temp_sum
        return my_list
</code></pre>
