Created
April 9, 2019 18:28
-
-
Save gyli/0254c32d9d8c390952124a5be99f9c0f to your computer and use it in GitHub Desktop.
Join list of strings with None
This file contains hidden or 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 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