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