Created
July 30, 2014 13:51
-
-
Save damnit/21d3fb2ec6306ca4b227 to your computer and use it in GitHub Desktop.
the functional approach of ".".join
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 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