3 ms·
I typically do, but i don't know if it is the most "pythonic" def func(list_arg=None, dict_arg=None): list_arg = list_arg or [] dict_arg = dic
by emehrkay 10y ago
I typically do, but i don't know if it is the most "pythonic"
def func(list_arg=None, dict_arg=None):
list_arg = list_arg or []
dict_arg = dict_arg or {}
- moreati 10y agoIt's not ideal. For instance if I as the caller wished to provide an empty dict-like object (e.g. dict_arg=collections.OrderedDict()), then your code would silently ignore it, and use a new dict. Instead of checking for any object that evaluates to False, you should explicitly check for None, e.g. def func(list_arg=None, dict_arg=None): if list_arg is None: list_arg = [] ...