Python: Functions used on each element of list x vs Functions that take list x as arg

Viewed 33

Is there any reason to choose one style over the other? Example:

def add_10(x):
    return x + 10

results = [add_10(i) for i in range(5)]

VS

def add_10(list_):
   return [e + 10 for e in list_]

results = add_10(range(5))

This is a basic example, but it illustrates the idea. I have been using the former recently because I just like writing functions with simple inputs and outputs (not that lists are complicated), but I don't know if there are any real pro's or con's to it other than personal style. I see more of the latter in documentation and other people's code, but I can't find any resources that address this specific idea.

Thanks

1 Answers
Related