
Even though we know so much about Python but we often find ourselves using only a few concepts in our day-to-day work. I believe that learning should be made simple and easy so that we can remember to apply it when faced with similar situations.
Today, We will discuss about three very famous functions in Python – Map, Filter and Reduce. These are also called as Higher-order functions. Now, What are these?
Higher-order functions
Functions that accept other functions as arguments are known as higher-order functions. This ability to pass function objects as arguments to other functions is quite powerful. It enables you to abstract and use within your programs. I am giving you a simplest example below, we will discuss Map function in detail in a while-
list(map(uppercase, ['apple', 'banana', 'orange']))
['APPLE', 'BANANA', 'ORANGE']
Map
This function accepts a function and an iterable. It then applies that function to every element in the iterable, and returns a new iterable., such as a list.
SYNTAX: map(function, iterables)
Suppose you have a list of product prices in USD, and you want to convert them to Euros using the current exchange rate. You can use Map function for this:
prices_usd = [10, 20, 30, 40, 50]
cur_exchange_rate = 0.84 #(1 USD = 0.84 Euros)
prices_eur = list(map(lambda x: round(x * cur_exchange_rate, 2), prices_usd))
print(prices_eur)
Output: [8.4, 16.8, 25.2, 33.6, 42.0]
Filter
This function accepts a function and an iterable. It acts as a filter, allowing only elements from that iterable that meet a specified condition to pass through.
SYNTAX: filter (function, iterables)
Imagine you have a list of employee ages, and you want to filter out only those who are eligible for retirement (age 65 and above):
employee_ages = [56, 62, 70, 45, 68, 72]
retirement_eligible = list(filter(lambda x: x >= 65, employee_ages))
print(retirement_eligible)
Output: [70, 68, 72]
Reduce
The Reduce function aggregates elements of the iterable into a single value, just how an accountant sums up all the expenses.

SYNTAX: reduce(function, iterables)
Suppose that accountant is you and you have a list of order total amount, and you want to find the overall revenue generated, then you can do something like this-
from functools import reduce
order_totals = [100, 150, 200, 75, 125]
total_revenue = reduce(lambda x, y: x + y, order_totals)
print(total_revenue)
Output: 650
Conclusion
Map, Filter, and Reduce functions are very useful tools in Python for manipulating data effectively. So, next time you’re coding in Python, don’t forget about these helpful functions to make your work smoother!
Happy Learning 🙂