Python comma separated join issue when only one value

Viewed 26

I've got the following line which takes 4 address lines and separates them with a comma.

compAddr = ', '.join(filter(None, (result[row][4], result[row][5], result[row][6], result[row][7])))

This works well except when only one of the lines is populated, then you still get a comma with a few spaces after the first value.

For example if I input "1 Baker Street" in the first value, and the rest are empty strings, the output is "1 Baker Street , "

Whats the simplest way to only output the first value without the comma if its the only one with anything in it?

0 Answers
Related