Hi, I recently realised one can use immutable default arguments to avoid a chain of:

def append_to(element, to=None):
    if to is None:
        to = []

at the beginning of each function with default argument for set, list, or dict.

you are viewing a single comment's thread
view the rest of the comments
[–] [S] 1 point 1 year ago

Yeah, but you can also write it like I proposed which is less boilerplaty and gives the same advantages

  • source
  • parent