I am looking for some kind of "binary" (non-ternary) if
that allows to define list membership in Python, similar to how it works in list comprehensions. Consider the following piece of code:
abc = (1, 0, 2)
my_list = [i for i in abc if i]
# observed: [1, 2]
a = 1
b = 0
c = 2
my_list = ["d" if a; "e" if b; "f" if c]
# expected: ["d", "f"]
While the first block works, the second does not (not surprisingly). I would find this syntax quite pythonic, however. Is there anything that comes close to it, such as
my_list = ["d" if a else Nothing; "e" if b else Nothing; "f" if c else Nothing]