how to add if and else in python list comprehension code example Example: if else in list comprehension [f(x) if condition else g(x) for x in sequence]