How can I fix my function?
<p>I am being told.. from comments to fix my function to make it look "cleaner". I've tried alot.. but i don't know how to use llambda to accomplish what I'm trying to do. My code works.. it just isn't what is being asked of me. </p>

<p>Here is my code with suggestions on how to fix it.</p>

<pre><code>def immutable_fibonacci(position):

    #define a lambda instead of def here
    def compute_fib (previousSeries, ignore):
        newList = previousSeries

        if len(newList) &lt; 2: # Do this outside and keep this function focused only on returning a new list with last element being sum of previous two elements
           newList.append(1)

        else:
           first = newList[-1]
           second = newList[-2]
           newList.append(first+second)
        return newList

    range=[None]*position
    return reduce(compute_fib, range, []) 

#Above is too much code. How about something like this:
#next_series = lambda series,_ : (Use these instead of the above line)
#return reduce(next_series, range(position - 2), [1, 1])
</code></pre>

<p>Anything helps.. I am just confused on how I can implement these suggestions. </p>

<p>Here is what I attempted.</p>

<pre><code>def immutable_fibonacci(position):
    range=[None]*position
    next_series = lambda series, _ : series.append(series[-1] + series[-2])
    return reduce(next_series, range(position - 2), [1, 1])
</code></pre>

<p>The <code>append</code> function returns None. You need to return a renewed array</p>

<pre><code>next_series = lambda series: series + [series[-1] + series[-2]]
</code></pre>

<p>Also renaming <code>range</code> isn't serving any purpose.</p>

<pre><code>def immutable_fibonacci(position):
    next_series = lambda series: series + [series[-1] + series[-2]]
    return reduce(next_series, range(position - 2), [1, 1])
</code></pre>

<p>This is assuming you only call the function for positions >= 2. Conventionally fib(0) is 0 and fib(1) is 1.</p>

python function