Apply a Custom Function to a List in Python

  • Post category:List

We can apply a function to each element of a list in Python using a for loop or a list comprehension. Here are two examples:

Example 1:

Python

Output:

4

Example 2:

Python

Output:

[‘Apple’, ‘Banana’, ‘Orange’, ‘Kiwi’]