Skip to content

Instantly share code, notes, and snippets.

@damnit
Created July 30, 2014 13:51
Show Gist options
  • Save damnit/21d3fb2ec6306ca4b227 to your computer and use it in GitHub Desktop.
Save damnit/21d3fb2ec6306ca4b227 to your computer and use it in GitHub Desktop.
the functional approach of ".".join
def list_join(sep, items):
""" method wrapper for str.join alternative.
>>> foo = ['foo', 'bar', 'baz']
>>> sep = ","
>>> sep.join(foo)
'foo,bar,baz'
>>> list_join(',', foo)
'foo,bar,baz'
"""
return reduce(lambda x, y: '%s%s%s' % (x, sep, y), items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment