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
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › functions › map.html
map — Python Reference (The Right Way) 0.1 documentation
If one iterable is shorter than another it is assumed to be extended with None items. If function is None, the identity function is assumed; if there are multiple arguments, map() returns a list consisting of tuples containing the corresponding items from all iterables (a kind of transpose ...
🌐
Python
docs.python.org › 3 › c-api › mapping.html
Mapping Protocol — Python 3.14.3 documentation
3.14.3 Documentation » · Python/C API reference manual » · Abstract Objects Layer » · Mapping Protocol · | Theme · Auto · Light · Dark | See also PyObject_GetItem(), PyObject_SetItem() and PyObject_DelItem(). int PyMapping_Check(PyObject *o)¶ · Part of the Stable ABI.
🌐
Real Python
realpython.com › python-map-function
Python's map(): Processing Iterables Without a Loop – Real Python
July 31, 2023 - According to the documentation, map() takes a function object and an iterable (or multiple iterables) as arguments and returns an iterator that yields transformed items on demand.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-map-function
Python map() function - GeeksforGeeks
map() function in Python applies a given function to each element of an iterable (list, tuple, set, etc.) and returns a map object (iterator).
Published   5 days ago
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']]
🌐
Python documentation
docs.python.org › 3 › library › functions.html
Built-in Functions — Python 3.14.3 documentation
3 weeks ago - Rather than being a function, list is actually a mutable sequence type, as documented in Lists and Sequence Types — list, tuple, range. ... Return a mapping object representing the current local symbol table, with variable names as the keys, and their currently bound references as the values.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-map-function
Python map() function | DigitalOcean
August 3, 2022 - Python map() function is used to apply a function on all the elements of specified iterable and return map object. Python map object is an iterator, so we can iterate over its elements. We can also convert map object to sequence objects such as list, tuple etc.
🌐
W3Schools
w3schools.com › python › ref_func_map.asp
Python map() Function
Python Examples Python Compiler ... Python Bootcamp Python Certificate Python Training ... The map() function executes a specified function for each item in an iterable....
Find elsewhere
🌐
GitHub
gist.github.com › 89465127 › 5275551
Examples of map() built-in that follow the official python documentation at http://docs.python.org/2/library/functions.html#map · GitHub
Examples of map() built-in that follow the official python documentation at http://docs.python.org/2/library/functions.html#map - map_example.py
🌐
Python Tips
book.pythontips.com › en › latest › map_filter.html
4. Map, Filter and Reduce — Python Tips 0.1 documentation
In 325+ pages, I will teach you ... approach to programming. We will discuss them one by one and understand their use cases. Map applies a function to all the items in an input_list....
🌐
Programiz
programiz.com › python-programming › methods › built-in › map
Python map() Function
The map() function executes a given function to each element of an iterable (such as lists,tuples, etc.).
🌐
Codecademy
codecademy.com › docs › python › built-in functions › map()
Python | Built-in Functions | map() | Codecademy
March 25, 2022 - The map() built-in function accepts a function and applies it to every item in an iterable. It outputs a map object. ... Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
🌐
Tutorial Teacher
tutorialsteacher.com › python › python-map-function
Python map() Function (With Examples)
Regex in Python · Create GUI using ... Update · Bulk Merge · The map() function applies the specified function to every item of the passed iterable, yields the results, and returns an iterator....
🌐
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 - We can use the Python built-in function map() to apply a function to each item in an iterable (like a list or dictionary) and return a new iterator for retrieving the results. map() returns a map object (an iterator), which we can use in other parts of our program.
🌐
Apache
beam.apache.org › documentation › transforms › python › elementwise › map
Map - Apache Beam®
Map accepts a function that returns a single element for every input element in the PCollection.
🌐
Earth Data Science
earthdatascience.org › home
Interactive Maps in Python | Earth Data Science - Earth Lab
February 5, 2018 - There are two great Python packages for creating interactive maps: folium and mapboxgl. Both of these packages are build on top off the JavaScript library called leaflet.js. This lesson will focus on folium, which has been around longer than mapboxgl and thus, is well-documented by the Python ...
🌐
DataCamp
datacamp.com › tutorial › python-map-function
Python map() Function: A Complete Guide | DataCamp
December 10, 2025 - The map() function requires at least two parameters: a callable function and an iterable. Optional additional iterables allow broadcasting the function across zipped sequences, which are perfect for vectorized operations akin to NumPy's apply_along_axis(). In Python 3, map() returns a map object, an iterator subclass, rather than a list...
🌐
Simplilearn
simplilearn.com › home › resources › software development › map function in python: simplify iterative operations
Map Function in Python: Simplify Iterative Operations
February 14, 2026 - 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