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
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 Β  September 7, 2025
🌐
Python.org
discuss.python.org β€Ί python help
The map() function or the list comprehension? - Python Help - Discussions on Python.org
September 12, 2023 - There are two ways to apply a function to each element of an iterated object in python: the map function: >>> lst = [1, 2, 3, 4] >>> list(map(str, lst)) ['1', '2', '3', '4'] >>> list(map(lambda a: a + 1, lst)) [2, 3, 4, 5] the list comprehension: ...
Discussions

Getting a map() to return a list in Python 3.x - Stack Overflow
I'm trying to map a list into hex, and then use the list elsewhere. In python 2.6, this was easy: A: Python 2.6: >>> map(chr, [66, 53, 0, 94]) ['B', '5', '\x00', '^'] However, in Python ... More on stackoverflow.com
🌐 stackoverflow.com
What does list(map(int,input().split())) do in python?
Let's break it down: input() gets user input and returns a string, e.g. "1 2 3 4 5" input().split() splits that input on whitespaces, e.g. ["1", "2", "3", ...] int() converts a string to a integer, e.g. "1" -> 1 map(fn, sequence) applies the function fn to each element in the sequence, e.g. fn(sequence[0]), fn(sequence[1]), ... map(int, input().split()) applies int to each string element in the input, e.g. ["1", "2", "3", ...] -> int("1"), int("2"), ... list() turns any iterator/generator to a list, e.g. int("1"), int("2"), ... => [1, 2, 3, ...] Example: In []: list(map(int, input().split())) Input: 1 2 3 4 5 Out[]: [1, 2, 3, 4, 5] Note: this is the same as, which may be easier to read: In []: [int(n) for n in input().split()] Input: 1 2 3 4 5 Out[]: [1, 2, 3, 4, 5] More on reddit.com
🌐 r/learnpython
13
16
September 17, 2020
DynamoDB, Python, adding a map to a list ... what am I doing wrong!
What errors are you getting? Are you using boto3's DynamoDB Client or Table resource? Try using Table resource . it's slightly easier than Client. More on reddit.com
🌐 r/aws
3
8
March 9, 2017
arr = map(int, input().split())

You don't create an array this way, you create an object that will provide you the objects once you iterate over them. Meaning as in a for loop

for v in arr:
    do something with v

or when you would create another sequence from it, like with list()

my_list = list(arr)

the point is that with a list you create a structure in RAM that will hold all the items upfront, which is often not what you actually need per se, so map allows you to simply define what you want (that takes no CPU or extra storage space) and only performs the actions when needed. If you do you need this as a list then a comprehension is preferable over map:

mylist = [int(n) for n in input.split()]

Sidenote: Python doesn't have a regular 'array', it has lists for ordered sequences that can be indexed. It does have specialized array for numerical values of a specific type but that's more oriented for low-level applications or for interfacing to other systems that need those kind of statically typed arrays.

More on reddit.com
🌐 r/learnpython
7
3
March 14, 2018
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']]
🌐
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.
🌐
Python documentation
docs.python.org β€Ί 3 β€Ί tutorial β€Ί datastructures.html
5. Data Structures β€” Python 3.14.3 documentation
Similarly to list comprehensions, set comprehensions are also supported: >>> a = {x for x in 'abracadabra' if x not in 'abc'} >>> a {'r', 'd'} Another useful data type built into Python is the dictionary (see Mapping Types β€” dict).
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-lambda-anonymous-functions-filter-map-reduce
Python Lambda Functions - GeeksforGeeks
map() iterates through a and applies the transformation. reduce() function repeatedly applies a lambda expression to elements of a list to combine them into a single result. ... The lambda multiplies two numbers at a time.
Published Β  5 days ago
Find elsewhere
🌐
Note.nkmk.me
note.nkmk.me β€Ί home β€Ί python
Apply a Function to Items of a List in Python: map() | note.nkmk.me
May 15, 2023 - In Python, you can use map() to apply built-in functions, lambda expressions (lambda), functions defined with def, etc., to all items of iterables, such as lists and tuples. Built-in Functions - map() ...
🌐
Mimo
mimo.org β€Ί glossary β€Ί python β€Ί map-function
Python Map Function: Streamline Data Transformation Efforts
With Python lists, map() allows you to process multiple lists simultaneously by passing multiple sequences.
🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί python-map-explained-with-examples
Python map() – List Function with Examples
April 23, 2025 - It returns a new iterable (a map object) that you can use in other parts of your code. ... Let's see an example: imagine you have a list of numbers, and you want to create a new list with the cubes of the numbers in the first list.
🌐
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.
🌐
W3Schools
w3schools.com β€Ί python β€Ί ref_func_map.asp
Python map() Function
Remove List Duplicates Reverse ... Python Bootcamp Python Certificate Python Training ... The map() function executes a specified function for each item in an iterable....
🌐
Medium
medium.com β€Ί @rahulkp220 β€Ί list-comprehensions-lambda-filter-map-and-reduce-functions-in-python-d7a1bc6cd79d
List Comprehensions, lambda, filter, map and reduce functions in Python | by Rahul Lakhanpal | Medium
April 19, 2016 - Lets walk through an example. ... map() function maps the function call on every element of the list. Here map() applies the function lambda x: x+1 on my_list elements,which increments each element by 1.
🌐
Johnsteen
johnsteen.co β€Ί essays β€Ί python-map.html
What's the fastest way to map a list of values in Python?
Python's built-in map() function takes in an iterable and a function, applies the function to every element and then returns an iterator with all of the modified elements. map(function, iterable, ...) This seems like a natural choice for what ...
🌐
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.).
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-map-vs-list-comprehension
Map vs List comprehension - Python - GeeksforGeeks
July 12, 2025 - ... Explanation: [x * 2 for x in numbers] iterates through each item in li. and x * 2 applies the transformation to each element. map() function applies a specified function to each element of an iterable and producing a map object.
🌐
Real Python
realpython.com β€Ί python-map-function
Python's map(): Processing Iterables Without a Loop – Real Python
July 31, 2023 - Even though the Python documentation calls this argument function, it can be any Python callable. This includes built-in functions, classes, methods, lambda functions, and user-defined functions. The operation that map() performs is commonly known as a mapping because it maps every item in an input iterable to a new item in a resulting iterable. To do that, map() applies a transformation function to all the items in the input iterable. To better understand map(), suppose you need to take a list of numeric values and transform it into a list containing the square value of every number in the original list.
🌐
Learn Python
learnpython.org β€Ί en β€Ί Map,_Filter,_Reduce
Map, Filter, Reduce - Learn Python - Free Interactive Python Tutorial
i.e. list(map(func, *iterables)) The number of arguments to func must be the number of iterables listed. Let's see how these rules play out with the following examples. Say I have a list (iterable) of my favourite pet names, all in lower case and I need them in uppercase. Traditonally, in normal pythoning, I would do something like this:
🌐
LearnDataSci
learndatasci.com β€Ί solutions β€Ί python-map
Python map(function, iterable, ...) – LearnDataSci
Let's look at another quick example. Assume we have a words list, and we want to calculate the length of each word to populate a word_lengths list. First, we'll split a string into words, then map the len() function to the collection, like so: