Jon-Eric’s answer’s is good for dicts, but the title seeks a general equivalent to ruby’s ||= operator.
A common way to do something like ||= in Python is
x = x or new_value
Jon-Eric’s answer’s is good for dicts, but the title seeks a general equivalent to ruby’s ||= operator.
A common way to do something like ||= in Python is
x = x or new_value