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