I very often come along the need to build statements like this in python:
kwargs['help'] = '' if 'help' not in kwargs else kwargs['help']
and I wonder if this is pythonic way to do this. I dont like the repetitive else part, but if I do
if 'help' not in kwargs:
kwargs['help'] = ''
this would be less repetitive but not really less verbose because its on two lines. And I really like in the first example, that it starts with the var assignment (which is the important thing that is happening here)
The problem is, I cant work with the and/or shortcircuiting when assigning variables
var or var = ''
wont work.
I would love to have something simple like:
var = '' if not var
so just without the else statement. But this is not implemented in python, so would be my way (first example) be considered pythonic, or should I use the two line if clause?