Is it possible to use ‘else’ in a list comprehension?
The syntax a if b else c is a ternary operator in Python that evaluates to a if the condition b is true – otherwise, it evaluates to c. It can be used in comprehension statements: So for your example,