Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

[] + [] is more likely to happen than taking list.append(value) and defining a function that does list.append(value) and then returns whatever list.append(value) returns.

Hint: list.append(value) returns None



`[] + []` is unlikely to happen except by accident if you don't know that's how array concatenation is done in JavaScript.

But wanting to provide default values of [] is quite common in Python. Seeing this workaround is quite common in Python:

    def func(arg=None): 
        if arg is None: 
            arg = [] 
        ...


I'm talking about the following where we don't intend to do [] + [] but we feed some lists to some functions that do something to the lists and we end up with empty lists in some cases without inspecting the contents of a and b after we feed it to the functions. Why would you define a default argument of an empty list if you're not gonna check if it's a list and if it's empty?

    a = [1,2]
    someFunction(a)
    b = [3,4]
    someOtherFunction(b)
    a + b




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: