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.

  • Narann@jlai.lu
    link
    fedilink
    arrow-up
    0
    ·
    9 days ago

    This is the way you’re supposed to write it in Python.

    It is something you get used to, yet I think it’s sad.