I program in python for a while and I've found that this language is very programmer friendly, so that maybe there is a technique that I don't know how to compose a list with conditional elements. The simplified example is:
# in pseudo code
add_two = True
my_list = [
"one",
"two" if add_two,
"three",
]
Basically I'm looking for a handy way to create a list that contains some that are added under some specific condition.
Some alternatives that don't look such nice:
add_two = True
# option 1
my_list = []
my_list += ["one"]
my_list += ["two"] if add_two else []
my_list += ["three"]
# option 2
my_list = []
my_list += ["one"]
if add_two: my_list += ["two"]
my_list += ["three"]
Is there something that can simplify it? Cheers!