input = "foo ,,bar ,baz,"
tags = [x.strip() for x in input.split(',') if len(x.strip()) > 0]
Desired output is obviously a list with no empty strings in it.
The question is in the spirit of micro optimisation; is there a way to not strip() the candidate x twice, ie once for the test and once for the append?
To rephrase, can you produce a value in the expressions that can be appended to the list without doing the work twice?
Creating a new string is always going to be more expensive than scanning it.
x.isspace()will return after the first not space character is encountered