I want to do something like this:
a = some_funct()
b = [ 1, a if a is not None ]
The list b should be one element long if a is None, and two elements long if a is not None. Is this possible in Python or do I have to use a separate if check followed by add()?
b = [1]; if a is not None: b.append(a)
? – Psidom 18 hours agob = [x for x in (1, a) if x is not None]
... but check-then-append is going to be more readable. – Zero Piraeus 18 hours ago