CSc 120: List to String (Recursive)
Expected Behavior
Write a recursive function list2string(arglist), where
arglist is a list of strings, that returns the string resulting from
concatenating the elements of arglist.
Programming Requirements
Solve this problem using recursion. You are allowed to use only
the following programming constructs:
-
if statements;
-
return statements;
-
assignment;
-
recursive function calls (but not to helper functions);
-
comparison operations (==, !=, etc.);
-
list indexing and slicing;
-
list and string concatenation.
Solutions that go outside these constructs, e.g., by
using for/while loops or list comprehensions,
will not get credit.
Examples
-
list2string(['aa','bb','cc','dd'])
return value: 'aabbccdd'
-
list2string(['aa','bb','','cc','','dd'])
return value: 'aabbccdd'
-
list2string(['aa'])
return value: 'aa'
-
list2string([])
return value: ''
-
list2string(['',''])
return value: ''