Map Function

Last Updated: 02th September 2025


A map function is a function that applies a function to each element of an iterable and returns a new iterator object.It is a Higher-Order Function.

Syntax:

map(function, iterable)

Example 1.

numbers = [1, 2, 3, 4, 5]
squared = list(map(lambda x: x ** 2, numbers))
print(squared)  # [1, 4, 9, 16, 25]

Example 2.

def add(x, y):
    return x + y

result = map(add, [1, 2, 3], [4, 5, 6])
print(list(result))  # [5, 7, 9]

Example 3.

words = ["python", "map", "function"]

result = map(str.upper, words)
print(list(result))
# Output: ['PYTHON', 'MAP', 'FUNCTION']

Example 4.

data = ["  Python ", " Map  ", " FUNCTION  "]

# strip spaces and convert to lower
result = map(lambda x: x.strip().lower(), data)
print(list(result))
# Output: ['python', 'map', 'function']