Any idea if it's possible to shorten and prettify this one (an extra variant assumes nested if-else conditions and more lists)?
some_list, some_other_list = [], []
if condition:
some_list.append(value)
else:
some_other_list.append(value)
Ternary expression:
(some_list if condition else some_other_list).append(value)
Explanation:
>>> condition = True
>>> ("A" if condition else "B")
A
>>> condition = False
>>> ("A" if condition else "B")
B
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With