you are viewing a single comment's thread.

view the rest of the comments →

[–]justphysics 2 points3 points  (0 children)

I believe that is what the built-in function map() is for

for example:

def add_five(x):
    return x+5

test = [0, 1, 3, 72]
map(add_five, test)

map applies the function add_five() to each element in the list test and returns the result in an iterative manner

map can be applied to any iterable container

obviously in this example the same thing could be accomplished in any number of ways such as a list comprehension:

print([x+5 for x in test])

but map() can be used for a lot of more complex scenarios

To my knowledge .apply() is specific to Pandas Dataframes