Cool things you can do with map in python
4 min readSep 28, 2021
What is a map() function?
The map() function will take two arguments one a function and another an iterable (list, tuple, etc), and performs the function passed to each item of the iterable and returns a map object.
The map object can take different types of functions. They are
- A normal function
- A lambda function
- A built-in function
- A filter function
The main purpose of using the map function is to perform operations on the iterables without manually having to iterate over them.
Let us look at some of the cool things we can do with map functions with different types of functions.
Map with normal functions
Square the numbers in the list using a normal function
In this example, we are calculating the square of a number using a separate function and returning it. The map() function will take this function as its first argument.