python join multiple strings ignore none and empty string

Solutions on MaxInterview for python join multiple strings ignore none and empty string by the best coders in the world

showing results for - "python join multiple strings ignore none and empty string"
Pietro
22 Sep 2020
1>>> strings = ['foo','','bar','moo']
2>>> ' '.join(filter(None, strings))
3'foo bar moo'
4
Josefa
08 Oct 2020
1# Concatenates string variables a and b with ' - ' or Coalesces them if one is None
2'-'.join([x for x in (a,b) if x])
3