def strings_in_a_list(n, s):
"""
----------------------------
Creates a Python list with a string, s, repeated n times. Uses recursion.
Use: list = strings_in_a_list (n, s)
-----------------------------
Preconditions:
n - a nonnegative integer (int)
s - a string (str)
Postconditions:
returns
l - a list with n copies of the string s (list of string)
-----------------------------
"""
l = []
l.append(s)
if len(l) != n:
l = l * n
return l
Would this be an acceptable recursive function, if no would you be able to show me a better and proper way of doing this? Thanks in advance.
output should be like this example:
strings_in_a_list(3, 'Dream') should return the list ['Dream', 'Dream', 'Dream']