7 ms·
Basically. The idiomatic solution for this in python is: def fn(x, my_dict=None): if my_dict is None: my_dict = {} ...
by jvdongen 13y ago
Basically. The idiomatic solution for this in python is:
def fn(x, my_dict=None):
if my_dict is None:
my_dict = {}
...
- brownbat 13y agoYou can use a sentinel if you want to allow None as an argument. More on that, along with a way to use mutable defaults productively: http://effbot.org/zone/default-values.htm http://effbot.org/zone/default-values.htm