This post will discuss how to apply a function to each member of a list in Python.

1. Using map() function

The standard solution is to use the map() function, which applies a function to every item of iterable and yield the results. The following code converts a list of lowercase characters to a list of uppercase characters:

Download  Run Code

2. Using List Comprehension

You can also use list comprehension to construct a new list, where each element results from some function applied to each member of the given list. Following is a simple example demonstrating usage of this function:

Download  Run Code

3. Using lambda function

Another plausible way of mapping is to create small anonymous functions using the lambda function. This is often useful when the conversion function is not available. To illustrate, the following code increments all values in the list by one.

Download  Run Code

That’s all about applying a function to each member of a list in Python.