by rectangletangle · 12y ago · 0 comments
foo = bar if qux is None else baz
They're particularly interesting when combined with comprehensions. ['a' if i % 2 == 0 else 'b' for i in range(10)]
Though this particular example can be expressed much more concisely. ['a', 'b'] * 5 foo = [baz, bar][qux is None] foo = qux == NULL ? bar : baz;
Of course, C does not do list comprehensions. ['a' if i % 2 == 0 else 'b' for i in range(10)]
very cool!I was only aware of code like
['a' for i in range(10) if i % 2 == 0] ['a' if i % 2 == 0 else 'b' for i in range(10)]
very cool!I was on aware of code like
['a' for i in range(10) if i % 2 == 0]