Skip to content

Instantly share code, notes, and snippets.

@Bamco
Created August 1, 2013 09:06
Show Gist options
  • Save Bamco/6129737 to your computer and use it in GitHub Desktop.
Save Bamco/6129737 to your computer and use it in GitHub Desktop.
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