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
print func(3, 'aaa')
returns
['aaa', 'aaa', 'aaa']
This is what I've done so far:
def func(times, data):
if times > 0:
return data.split() + func(times-1, data)
However, it's giving me a TypeError:
can only concatenate list (not "NoneType") to list.
I'm still a novice and I just read about recursion.
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!

times == 0? You are not returning anything in that case.['aaa']*3[data]*timesis probably the best way to do it otherwise.def func(nb,s): return [s]*nb print(func(3, 'aaa'))