Map : Python Basics
Mar 21, 2022
Map is another one of those things that make python “pythonic”.
Map applies a certain function to each item of an iterable. Map takes a minimum of 2 arguments : a function and a iterable (list, tuple, dict) and it returns a map object.
Example
Map in often used in conjunction with lambda. Below example shows 3 different types of functions passed to map :
- with a python pre-defines function
- with a lambda function
- with a user defines function (def keyword)
Lastly let’s take a scenario where the function passed to map requires 2 or more arguments, here we simply need to pass all the iterables instead of just one.