Created
August 1, 2013 09:06
-
-
Save Bamco/6129737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def concat(separator, lst): | |
""" | |
Takes string separator and list of strings and retuns one big string with | |
all the string elements of lst concatenated together, but separated by the | |
string separator. | |
This implementation is kinda *functional*. | |
Examples: | |
concat('...', []) -> "" | |
concat('...', ["Test"]) -> "Test" | |
concat('+', ["One", "Two", "Three"]) -> "One+Two+Three" | |
""" | |
if len(lst) == 0: return "" | |
elif len(lst) == 1: return lst[0] | |
else: return lst[0] + separator + concat(separator, lst[1:]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment