---
description: Python map() applies a function on all the items of an iterator given as input. An iterator, for example, can be a list, a tuple, a set, a dictionary, a string, and it returns an iterable map object.
title: Python map() Function with EXAMPLES
image: https://www.guru99.com/images/python-map-function.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Python map() applies a given function to every item of an iterable such as a list, tuple, set, dictionary, or string. It returns a lazy map object that you convert with list() or iterate using a loop.

* 🔢 **Syntax:** map() takes a function plus one or more iterables and applies that function to each element.
* 🔁 **Return value:** map() returns a lazy map object, so wrap it in list(), tuple(), or set() to view the results.
* 🧩 **Iterables:** Lists, tuples, sets, dictionaries, and strings all work as inputs to map().
* ⚡ **Lambda:** Pairing map() with a lambda avoids defining a separate named function for simple transformations.
* ➕ **Multiple iterables:** Passing several iterables applies the function across them in parallel, stopping at the shortest.
* 🤖 **AI assistance:** AI assistants such as GitHub Copilot generate map() calls, and map-style transforms feed data pipelines in machine learning.

[ Read More ](javascript:void%280%29;) 

![Python map\(\) Function](https://www.guru99.com/images/python-map-function.png)

## Syntax

map(function, iterator1,iterator2 ...iteratorN)

### Parameters

Here are two important parameters:

* **function:** A mandatory function to be given to map(), which will be applied to all the items available in the iterator.
* **iterator:** A compulsory iterable object. It can be a list, a tuple, etc. You can pass multiple iterator objects to the map() function.

### Return Value

The map() function applies the given function on all the items inside the iterator and returns an iterable map object, i.e., a tuple, a list, etc.

## How map() function works?

The map() function takes two inputs: a function and an iterable object. The function given to map() is a normal function, and it iterates over all the values present in the iterable object.

For example, consider you have a list of numbers, and you want to find the square of each of the numbers.

To get the output, we need a function that will return the square of the given number. The function is as follows:

def square(n):
	return n*n

The list of items for which we want to find the square is as follows:

my_list = [2,3,4,5,6,7,8,9]

Now let us use the map() built-in function to get the square of each of the items in my\_list.

The final code is as follows:

def square(n):
    return n*n
my_list = [2,3,4,5,6,7,8,9]
updated_list = map(square, my_list)
print(updated_list)
print(list(updated_list))

**Output:**

<map object at 0x0000002C59601748>
[4, 9, 16, 25, 36, 49, 64, 81]

The output of the map() function, as seen above, is a map object displayed on the screen as <map object at 0x0000002C59601748>.

You will have to iterate the output from map() using a for-loop or the list() method to get the final output. I have used list() in the code to display the values inside the given list.

So using the map() function, we are able to get the square of each number. The list given to map() was \[2,3,4,5,6,7,8,9\], and using the function square(), the output we got is \[4, 9, 16, 25, 36, 49, 64, 81\].

The map() function applies the function square() on all the items in the list. For example, it takes the my\_list variable and updates the list with the square of each number. The output is stored in the updated\_list variable.

## Using map() with Python built-in functions

The Python map() function is a built-in function and can also be used with other built-in functions available in Python. In this example, we are going to make use of the Python round() built-in function that rounds the given values.

**Example:**

The list that I have is my\_list = \[2.6743,3.63526,4.2325,5.9687967,6.3265,7.6988,8.232,9.6907\]. I need the rounded values for each item present in the list, so we will make use of round() as the function to map().

my_list = [2.6743,3.63526,4.2325,5.9687967,6.3265,7.6988,8.232,9.6907]
updated_list = map(round, my_list)
print(updated_list)
print(list(updated_list))

**Output:**

<map object at 0x000000E65F901748>
[3, 4, 4, 6, 6, 8, 8, 10]

The round() function is applied to all the items in the list, and it returns a list with all values rounded, as shown in the output.

### RELATED ARTICLES

* [Python Check if File Exists (with Examples) ](https://www.guru99.com/python-check-if-file-exists.html "Python Check if File Exists (with Examples)")
* [Python Timeit() with Examples ](https://www.guru99.com/timeit-python-examples.html "Python Timeit() with Examples")
* [Python String count() with EXAMPLES ](https://www.guru99.com/python-string-count.html "Python String count() with EXAMPLES")
* [Palindrome Program in Python ](https://www.guru99.com/palindrome-program-in-python.html "Palindrome Program in Python")

## Using map() with a string as an iterator

We can also make use of map() on a string. In Python, a string acts like an array, so we can easily use it inside map().

In this example, we have a function myMapFunc() that takes care of converting the given string to uppercase. The function myMapFunc() is given to the map() function. The map() function will take care of converting the given string to uppercase by passing the string to myMapFunc().

def myMapFunc(s):
    return s.upper()
my_str = "welcome to guru99 tutorials!"
updated_list = map(myMapFunc, my_str)
print(updated_list)
for i in updated_list:
    print(i, end="")

**Output:**

<map object at 0x000000DF2E711748>
WELCOME TO GURU99 TUTORIALS!

## Using map() with a List of Numbers

To work with a list in map(), we will take a list of numbers and multiply each number in the list by 10.

The list that we are going to use is \[2,3,4,5,6,7,8,9\]. The function myMapFunc() takes care of multiplying the given number by 10\. The function is given to map() along with the list.

**Example:**

def myMapFunc(n):
    return n*10

my_list = [2,3,4,5,6,7,8,9]

updated_list = map(myMapFunc, my_list)
print(updated_list)
print(list(updated_list))

**Output:**

<map object at 0x000000EE2C061898>
[20, 30, 40, 50, 60, 70, 80, 90]

The output we see is that each number in the list is multiplied by 10.

## Using map() with Tuple

A tuple is an object in Python that has items separated by commas and enclosed in round brackets. In this example, we will take a tuple with string values. The function that we will use will convert the given values to uppercase.

**Example:**

def myMapFunc(n):
    return n.upper()

my_tuple = ('php','java','python','c++','c')

updated_list = map(myMapFunc, my_tuple)
print(updated_list)
print(list(updated_list))

**Output:**

<map object at 0x0000009C3C3A16A0>
['PHP', 'JAVA', 'PYTHON', 'C++', 'C']

The output we get is a tuple back with all the values in it converted to uppercase.

## Using map() with Dictionary

A [dictionary in Python](https://www.guru99.com/python-dictionary-beginners-tutorial.html) is created using curly brackets ({}). Since the dictionary is an iterator, you can make use of it inside the map() function. Let us now use a dictionary as an iterator inside map().

The following example shows the working of a dictionary iterator inside map():

def myMapFunc(n):
    return n*10
my_dict = {2,3,4,5,6,7,8,9}
finalitems = map(myMapFunc, my_dict)
print(finalitems)
print(list(finalitems))

**Output:**

<map object at 0x0000007EB451DEF0>
[20, 30, 40, 50, 60, 70, 80, 90]

## Using map() with Set

A set in Python is an unordered collection of items in curly brackets ({}). Since set() is also an iterator, you can make use of it inside the map() function.

Here is a working example of using a set as an iterator inside map():

def myMapFunc(n):
    return n*10
my_set = {2,3,4,5,6,7,8,9}
finalitems = map(myMapFunc, my_set)
print(finalitems)
print(list(finalitems))

**Output:**

<map object at 0x000000AC8F05DEF0>
[20, 30, 40, 50, 60, 70, 80, 90]

## Using map() with Lambda function

In Python, lambda expressions are utilized to construct anonymous functions. You will have to use the lambda keyword just as you use def to define normal functions.

So in this example, we are going to use the lambda function inside map(). The lambda function will multiply each value in the list by 10.

**Example:**

my_list = [2,3,4,5,6,7,8,9]
updated_list = map(lambda x: x * 10, my_list)
print(updated_list)
print(list(updated_list))

**Output:**

<map object at 0x000000BD18B11898>
[20, 30, 40, 50, 60, 70, 80, 90]

## Using Multiple Iterators inside map() function

### Example 1: Passing two list iterators to map()

You can send more than one iterator, i.e., a list, a tuple, etc., all at the same time to the map() function.

For example, if you want to add two lists, the same can be done using the map() function. We are going to make use of two lists, my\_list1 and my\_list2.

In the example below, the first item in my\_list1 is added to the first item of my\_list2\. The function myMapFunc() takes in items of my\_list1 and my\_list2 and returns the sum of both.

Here is the working example of adding two given lists using the map() function.

def myMapFunc(list1, list2):
    return list1+list2

my_list1 = [2,3,4,5,6,7,8,9]
my_list2 = [4,8,12,16,20,24,28]

updated_list = map(myMapFunc, my_list1,my_list2)
print(updated_list)
print(list(updated_list))

**Output:**

<map object at 0x0000004D5F751860>
[6, 11, 16, 21, 26, 31, 36]

### Example 2: Passing one Tuple and a list iterator to map()

We are going to make use of a list and a tuple iterator in the map() function. The function given to map(), myMapFunc(), will get the items from the list and the tuple. The items will be joined with an underscore (\_). The working example is shown below:

def myMapFunc(list1, tuple1):
    return list1+"_"+tuple1

my_list = ['a','b', 'b', 'd', 'e']
my_tuple = ('PHP','Java','Python','C++','C')

updated_list = map(myMapFunc, my_list,my_tuple)
print(updated_list)
print(list(updated_list))

**Output:**

<map object at 0x00000059F37BB4E0>
['a_PHP', 'b_Java', 'b_Python', 'd_C++', 'e_C']

## FAQs

⚖️ What is the difference between map() and a list comprehension in Python?

Both apply an operation to each item. A list comprehension is often more readable and returns a list directly, while map() returns a lazy map object and can be faster when reusing an existing named function.

🔁 Does the Python map() function modify the original iterable?

No. map() never changes the original iterable. It reads each element, applies your function, and produces a new lazy map object, leaving the source list, tuple, or string untouched.

🧵 Why does map() return a map object instead of a list in Python 3?

In Python 3, map() is lazy: it returns a map object that computes values only when iterated. This saves memory on large data. Wrap it in list() or loop over it to get results.

🔗 What is the difference between map(), filter(), and reduce() in Python?

map() transforms every item, filter() keeps only items passing a test, and reduce() (from functools) combines all items into a single value. Together they cover transform, select, and aggregate operations.

📏 What happens when map() iterables have different lengths?

When iterables differ in length, map() stops at the shortest one. Extra items in the longer iterables are ignored, so no error is raised and the result matches the shortest iterable.

♻️ Can you iterate over a Python map object more than once?

No. A map object is an iterator that is exhausted after one pass. Once you loop through it or call list() on it, it is empty. Convert it to a list first if you need reuse.

🤖 How is the map() function used in AI and machine learning?

In machine learning, map() applies preprocessing functions across datasets, such as scaling numbers, tokenizing text, or transforming features before training. It gives a clean, functional way to run the same operation over many samples.

🧠 Can GitHub Copilot or agentic AI tools write map() code automatically?

Yes. GitHub Copilot autocompletes map() calls with the right function and iterables, and agentic AI tools can refactor loops into map() expressions, then run your tests to confirm the behavior is unchanged.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter]() Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/python-map-function.png","url":"https://www.guru99.com/images/python-map-function.png","width":"700","height":"250","caption":"Python map() Function","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/python-map-function.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/python","name":"Python"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/python-map-function.html","name":"Python map() Function with EXAMPLES"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/python-map-function.html#webpage","url":"https://www.guru99.com/python-map-function.html","name":"Python map() Function with EXAMPLES","dateModified":"2026-07-10T13:15:52+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/python-map-function.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/python-map-function.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/logan","name":"Logan Young","description":"I'm Logan Young, an expert in Python, providing top-tier tutorials and guides to enhance your coding skills and streamline your learning journey.","url":"https://www.guru99.com/author/logan","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/logan-young-author.png","url":"https://www.guru99.com/images/logan-young-author.png","caption":"Logan Young","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"Python","headline":"Python map() Function with EXAMPLES","description":"Python map() applies a function on all the items of an iterator given as input. An iterator, for example, can be a list, a tuple, a set, a dictionary, a string, and it returns an iterable map object.","keywords":"python","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/logan","name":"Logan Young"},"dateModified":"2026-07-10T13:15:52+05:30","image":{"@id":"https://www.guru99.com/images/python-map-function.png"},"copyrightYear":"2026","name":"Python map() Function with EXAMPLES","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the difference between map() and a list comprehension in Python?","acceptedAnswer":{"@type":"Answer","text":"Both apply an operation to each item. A list comprehension is often more readable and returns a list directly, while map() returns a lazy map object and can be faster when reusing an existing named function."}},{"@type":"Question","name":"Does the Python map() function modify the original iterable?","acceptedAnswer":{"@type":"Answer","text":"No. map() never changes the original iterable. It reads each element, applies your function, and produces a new lazy map object, leaving the source list, tuple, or string untouched."}},{"@type":"Question","name":"Why does map() return a map object instead of a list in Python 3?","acceptedAnswer":{"@type":"Answer","text":"In Python 3, map() is lazy: it returns a map object that computes values only when iterated. This saves memory on large data. Wrap it in list() or loop over it to get results."}},{"@type":"Question","name":"What is the difference between map(), filter(), and reduce() in Python?","acceptedAnswer":{"@type":"Answer","text":"map() transforms every item, filter() keeps only items passing a test, and reduce() (from functools) combines all items into a single value. Together they cover transform, select, and aggregate operations."}},{"@type":"Question","name":"What happens when map() iterables have different lengths?","acceptedAnswer":{"@type":"Answer","text":"When iterables differ in length, map() stops at the shortest one. Extra items in the longer iterables are ignored, so no error is raised and the result matches the shortest iterable."}},{"@type":"Question","name":"Can you iterate over a Python map object more than once?","acceptedAnswer":{"@type":"Answer","text":"No. A map object is an iterator that is exhausted after one pass. Once you loop through it or call list() on it, it is empty. Convert it to a list first if you need reuse."}},{"@type":"Question","name":"How is the map() function used in AI and machine learning?","acceptedAnswer":{"@type":"Answer","text":"In machine learning, map() applies preprocessing functions across datasets, such as scaling numbers, tokenizing text, or transforming features before training. It gives a clean, functional way to run the same operation over many samples."}},{"@type":"Question","name":"Can GitHub Copilot or agentic AI tools write map() code automatically?","acceptedAnswer":{"@type":"Answer","text":"Yes. GitHub Copilot autocompletes map() calls with the right function and iterables, and agentic AI tools can refactor loops into map() expressions, then run your tests to confirm the behavior is unchanged."}}]}],"@id":"https://www.guru99.com/python-map-function.html#schema-1139315","isPartOf":{"@id":"https://www.guru99.com/python-map-function.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/python-map-function.html#webpage"}}]}
```
