Python recursion variable state
<p>I'm trying to write a Python function to take a string and a number and return a list containing repetitions of the string. For example</p>

<pre><code>print func(3, 'aaa')
</code></pre>

<p>returns</p>

<pre><code>['aaa', 'aaa', 'aaa']
</code></pre>

<p>This is what I've done so far:</p>

<pre><code>def func(times, data):
    if times &gt; 0:
        return data.split() + func(times-1, data)
</code></pre>

<p>However, it's giving me a TypeError:</p>

<pre><code>can only concatenate list (not "NoneType") to list.
</code></pre>

<p>I'm still a novice and I just read about recursion. </p>

<p>I would also like to know how to "carry over" the state of a variable from successive function calls, without having to define a global variable. Help please!</p>

<p>While @Padraic Cunningham has a good answer, here is a simple way to do it:</p>

<pre><code>def func(number, content):
    return [content] * number
</code></pre>

<p>Or list comprehension:</p>

<pre><code>def func(number, content):
    return [content for _ in range(number)]
</code></pre>

python