if else in a list comprehension python code example
Example 1: list comprehension python if else
[statement if condition else statement for _ in iterable_object]
#statement are without assignment
Example 2: else statement python list comprehension
>>> [a if a else 2 for a in [0,1,0,3]]
[2, 1, 2, 3]