Skip to content

Instantly share code, notes, and snippets.

@gyli
Created April 9, 2019 18:28
Show Gist options
  • Save gyli/0254c32d9d8c390952124a5be99f9c0f to your computer and use it in GitHub Desktop.
Save gyli/0254c32d9d8c390952124a5be99f9c0f to your computer and use it in GitHub Desktop.
Join list of strings with None
def join_nullable(l: List[str], sep: str) -> str:
"""
Filter out None in a list and join the remaining strings.
Example:
Input: l=['a', None, 'c'], sep=' '
Output: 'a c'
:param l: list of strings
:param sep: separator
"""
return sep.join(filter(lambda i: bool(i), l))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment