Apply a Function to a List in Python

  • Post category:List

Applying a function to each element of a list is a common task in Python programming. In this blog post, we’ll explore different code examples that demonstrate how to use list comprehension and the map() function to apply a function to each element of a list efficiently.

Example 1:

Python

Output: [1, 4, 9, 16, 25]

Example 2:

Python

Output: [‘ALICE’, ‘BOB’, ‘CHARLIE’]