I have four strings and any of them can be empty. I need to join them into one string with spaces between them. If I use:
new_string = string1 + \' \' + stri
>>> strings = ['foo','','bar','moo'] >>> ' '.join(filter(None, strings)) 'foo bar moo'
By using None in the filter() call, it removes all falsy elements.
None