python if else in list conprehension code example
Example 1: python list comprehension if else
# if/else
[f(x) if condition(x) else '' for x in sequence]
Example 2: if else in list comprehension
[f(x) if condition else g(x) for x in sequence]
# if/else
[f(x) if condition(x) else '' for x in sequence]
[f(x) if condition else g(x) for x in sequence]