Список понимания Python, если еще
[statement if condition else statement for _ in iterable_object]
#statement are without assignment
Angry Ant
[statement if condition else statement for _ in iterable_object]
#statement are without assignment
l = [22, 13, 45, 50, 98, 69, 43, 44, 1]
a = [x + 1 if x >= 45 else x + 5 for x in l]
>>> l = [1, 2, 3, 4, 5]
>>> ['yes' if v == 1 else 'no' if v == 2 else 'idle' for v in l]
['yes', 'no', 'idle', 'idle', 'idle']
["Even" if i%2==0 else "Odd" for i in range(8)]
[<Exp1> if condition else <Exp2> if condition else <Exp3> for <item> in <iterable>]