map isn't particularly pythonic. I would recommend using list comprehensions instead:

map(f, iterable)

is basically equivalent to:

[f(x) for x in iterable]

map on its own can't do a Cartesian product, because the length of its output list is always the same as its input list. You can trivially do a Cartesian product with a list comprehension though:

[(a, b) for a in iterable_a for b in iterable_b]

The syntax is a little confusing -- that's basically equivalent to:

result = []
for a in iterable_a:
    for b in iterable_b:
        result.append((a, b))
Answer from dave on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-map-function
Python map() function - GeeksforGeeks
By default, map() function returns a map object, which is an iterator. In many cases, we will need to convert this iterator to a list to work with the results directly. Example: Let's see how to double each elements of the given list.
Published ย  September 7, 2025
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_func_map.asp
Python map() Function
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training ... The map() function executes a specified function for each item in an iterable.
Top answer
1 of 6
529

map isn't particularly pythonic. I would recommend using list comprehensions instead:

map(f, iterable)

is basically equivalent to:

[f(x) for x in iterable]

map on its own can't do a Cartesian product, because the length of its output list is always the same as its input list. You can trivially do a Cartesian product with a list comprehension though:

[(a, b) for a in iterable_a for b in iterable_b]

The syntax is a little confusing -- that's basically equivalent to:

result = []
for a in iterable_a:
    for b in iterable_b:
        result.append((a, b))
2 of 6
99

map doesn't relate to a Cartesian product at all, although I imagine someone well versed in functional programming could come up with some impossible to understand way of generating a one using map.

map in Python 3 is equivalent to this:

def map(func, iterable):
    for i in iterable:
        yield func(i)

and the only difference in Python 2 is that it will build up a full list of results to return all at once instead of yielding.

Although Python convention usually prefers list comprehensions (or generator expressions) to achieve the same result as a call to map, particularly if you're using a lambda expression as the first argument:

[func(i) for i in iterable]

As an example of what you asked for in the comments on the question - "turn a string into an array", by 'array' you probably want either a tuple or a list (both of them behave a little like arrays from other languages) -

 >>> a = "hello, world"
 >>> list(a)
['h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd']
>>> tuple(a)
('h', 'e', 'l', 'l', 'o', ',', ' ', 'w', 'o', 'r', 'l', 'd')

A use of map here would be if you start with a list of strings instead of a single string - map can listify all of them individually:

>>> a = ["foo", "bar", "baz"]
>>> list(map(list, a))
[['f', 'o', 'o'], ['b', 'a', 'r'], ['b', 'a', 'z']]

Note that map(list, a) is equivalent in Python 2, but in Python 3 you need the list call if you want to do anything other than feed it into a for loop (or a processing function such as sum that only needs an iterable, and not a sequence). But also note again that a list comprehension is usually preferred:

>>> [list(b) for b in a]
[['f', 'o', 'o'], ['b', 'a', 'r'], ['b', 'a', 'z']]
๐ŸŒ
Real Python
realpython.com โ€บ python-map-function
Python's map(): Processing Iterables Without a Loop โ€“ Real Python
July 31, 2023 - This behavior changed in Python ... desired list object. For another example, say you need to convert all the items in a list from a string to an integer number....
๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ methods โ€บ built-in โ€บ map
Python map() Function
Here, the map() function squares each element of the tuple using the square function. The initial output <map object at 0x7f722da129e8> represents a map object ยท Finally, we convert the map object to a set and obtain the squared values of each element in tuple. Note: The output is not in order ...
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ how-to-use-the-python-map-function
Ultimate Guide to Python Map Function for Data Processing | DigitalOcean
December 18, 2024 - In the same way as lambda functions ... in another iterable name following the first one. For example, using the pow() function that takes in two numbers to find the power of the base number to the provided exponent....
๐ŸŒ
Enki
enki.com โ€บ post โ€บ apply-a-function-to-each-element-in-a-list---python-s-map-function
Enki | Blog - Apply a Function to Each Element in a List - Pythonโ€™s map function
In this example, map() applies the square function to every number in the list. The result shows how you can transform all list elements effortlessly. Lambda functions in Python offer a way to create small anonymous functions on the go.
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ pythoneers โ€บ understanding-how-maps-work-in-python-ce7102539bad
Understanding How Maps Work in Python | by Rajat Sharma | The Pythoneers | Medium
April 13, 2024 - Creating a map, or dictionary, in Python is straightforward. You can initialize an empty dictionary or create one with predefined key-value pairs using curly braces {} and colons : to separate keys and values, respectively. Here's an example:
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-map-function
Python map() Function: A Complete Guide | DataCamp
December 10, 2025 - If you want to build upon the new ... entire list in memory at once. For example, list(map(lambda x, y: x + y, [1, 2], [10, 20])) adds elements from two lists, resulting in [11, 22]....
๐ŸŒ
Geocompx
py.geocompx.org โ€บ 08-mapping
8 Making maps with Python โ€“ Geocomputation with Python
Letโ€™s move on to the basics of static mapping with Python. A vector layer (GeoDataFrame) or a geometry column (GeoSeries) can be displayed using their .plot method (Section 1.2.2). A minimal example of a vector layer map is obtained using .plot with nothing but the defaults (Figure 8.1).
๐ŸŒ
Python Reference
python-reference.readthedocs.io โ€บ en โ€บ latest โ€บ docs โ€บ functions โ€บ map.html
map โ€” Python Reference (The Right Way) 0.1 documentation
>>> map(None, [True, False]) [True, False] >>> map(None, ['a', 'b'], [1, 2]) [('a', 1), ('b', 2)] >>> map(None, ['a', 'b'], [1, 2, 3]) [('a', 1), ('b', 2), (None, 3)]
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ map function in python: simplify iterative operations
Map Function in Python: Simplify Iterative Operations
1 month ago - Learn how to use the map function in Python to simplify iterative operations. Discover its benefits, usage, and practical examples for efficient coding.
Address ย  5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
๐ŸŒ
Learn Python
learnpython.org โ€บ en โ€บ Map,_Filter,_Reduce
Map, Filter, Reduce - Learn Python - Free Interactive Python Tutorial
Let me clarify this with another example. Say I have a list of circle areas that I calculated somewhere, all in five decimal places. And I need to round each element in the list up to its position decimal places, meaning that I have to round up the first element in the list to one decimal place, the second element in the list to two decimal places, the third element in the list to three decimal places, etc. With map() this is a piece of cake. Let's see how. Python already blesses us with the round() built-in function that takes two arguments -- the number to round up and the number of decimal places to round the number up to.
๐ŸŒ
YouTube
youtube.com โ€บ watch
Python Map Function - YouTube
Learn how to use the Python map() function to apply a function to every value in an iterable, such as a list.Check out the written tutorial here: https://dat...
Published ย  May 16, 2022
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-map-explained-with-examples
Python map() โ€“ List Function with Examples
April 23, 2025 - An example of this would be the pow(x, y) function that takes in 2 arguments (it returns the result of x^y). To apply a function with multiple arguments, simply pass in another iterable name following the first one. base = [1, 2, 3, 4] power ...
๐ŸŒ
Python documentation
docs.python.org โ€บ 3 โ€บ library โ€บ functions.html
Built-in Functions โ€” Python 3.14.3 documentation
2 weeks ago - For example, delattr(x, 'foobar') is equivalent to del x.foobar. name need not be a Python identifier (see setattr()). ... Create a new dictionary. The dict object is the dictionary class. See dict and Mapping Types โ€” dict for documentation about this class.
๐ŸŒ
Medium
medium.com โ€บ @tanvijain17 โ€บ how-to-use-the-map-function-in-python-d8db02f12653
How to use the map function in Python | by Tanvi Jain | Medium
March 4, 2024 - Hereโ€™s an example where we use ... "orange", "grape", "kiwi"] # Map object containing lengths of strings lengths_map = map(len, words_list) # Converting map object to a set lengths_set = set(lengths_map) print(lengths_set) ...
๐ŸŒ
Python Cheatsheet
pythoncheatsheet.org โ€บ home โ€บ builtin โ€บ map
Python map() built-in function
def double_map(func, iter): my_map = map(func, iter) return list(my_map) def double(element): return element * 2 nums = [1, 2, 3, 4] print(double_map(double, nums))
๐ŸŒ
LearnDataSci
learndatasci.com โ€บ solutions โ€บ python-map
Python map(function, iterable, ...) โ€“ LearnDataSci
When you purchase through links ... Here's a quick example that uses map() to square all integers in a list: data = [1, 2, 3] squared = map(lambda x: x**2, data) print(list(squared)) Learn Data Science with ยท...