map() function returns a map object(which is an iterator) of the results after applying the given function to each item of a given iterable (list, tuple etc.)
Syntax :
map(fun, iter)
Parameters :
fun : It is a function to which map passes each element of given iterable.
iter : It is a iterable which is to be mapped.
NOTE : You can pass one or more iterable to the map() function.
Returns :
Returns a list of the results after applying the given function to each item of a given iterable (list, tuple etc.)
NOTE : The returned value from map() (map object) then can be passed to functions like list() (to create a list), set() (to create a set) .
CODE 1
# Python program to demonstrate working # of map. # Return double of n def addition(n): return n + n # We double all numbers using map() numbers = (1, 2, 3, 4) result = map(addition, numbers) print(list(result)) |
Output :
[2, 4, 6, 8]
CODE 2
We can also use lambda expressions with map to achieve above result.
# Double all numbers using map and lambda numbers = (1, 2, 3, 4) result = map(lambda x: x + x, numbers) print(list(result)) |
Output :
[2, 4, 6, 8]
CODE 3
# Add two lists using map and lambda numbers1 = [1, 2, 3] numbers2 = [4, 5, 6] result = map(lambda x, y: x + y, numbers1, numbers2) print(list(result)) |
Output :
[5, 7, 9]
CODE 4
# List of strings l = ['sat', 'bat', 'cat', 'mat'] # map() can listify the list of strings individually test = list(map(list, l)) print(test) |
Output :
[['s', 'a', 't'], ['b', 'a', 't'], ['c', 'a', 't'], ['m', 'a', 't']]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
Recommended Posts:
- Sum 2D array in Python using map() function
- Map function and Lambda expression in Python to replace characters
- Map function and Dictionary in Python to sum ASCII values
- Python map function to find row with maximum number of 1's
- Python map function | Count total set bits in all numbers from 1 to n
- Python - pass multiple arguments to map function
- Python lambda (Anonymous Functions) | filter, map, reduce
- Python | Plotting Google Map using gmplot package
- Python script to open a Google Map location on clipboard
- Python Map | Length of the Longest Consecutive 1's in Binary Representation of a given integer
- Python | Get a google map image of specified location using Google Static Maps API
- Python | Plotting Google Map using folium package
- Python | pandas.map()
- Python | Reverse Geocoding to get location on a map using geographic coordinates
- Python PIL | ImagePath.Path.map() method
- Python - Map vs List comprehension
- Python: Map VS For Loop
- Python OpenCV - Depth map from Stereo Images
- Python Bokeh – Plotting glyphs over a Google Map
- Plotting World Map Using Pygal in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.
