👻 *Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!*

```
map(function, iterable, ...)
```

Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed, function must take that many arguments and is applied to the items from all iterables in parallel.

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 operation).

The iterable arguments may be a sequence or any iterable object; the result is always a list.

What role does this play in making a Cartesian product?

```
content = map(tuple, array)
```

What effect does putting a tuple anywhere in there have? I also noticed that without the map function the output is `abc`

and with it, it"s `a, b, c`

.

I want to fully understand this function. The reference definitions is also hard to understand. Too much fancy fluff.

👻 *Read also: what is the best laptop for engineering students?*

## Understanding the map function cartesian product: Questions

Get the cartesian product of a series of lists?

1 answers

How can I get the Cartesian product (every possible combination of values) from a group of lists?

Input:

```
somelists = [
[1, 2, 3],
["a", "b"],
[4, 5]
]
```

Desired output:

```
[(1, "a", 4), (1, "a", 5), (1, "b", 4), (1, "b", 5), (2, "a", 4), (2, "a", 5) ...]
```

Answer #1

`itertools.product`

Available from Python 2.6.

```
import itertools
somelists = [
[1, 2, 3],
["a", "b"],
[4, 5]
]
for element in itertools.product(*somelists):
print(element)
```

Which is the same as,

```
for element in itertools.product([1, 2, 3], ["a", "b"], [4, 5]):
print(element)
```

We hope this article has helped you to resolve the problem. Apart from Understanding the map function, check other cartesian product-related topics.

Want to excel in Python? See our review of the best Python online courses 2022. If you are interested in Data Science, check also how to learn programming in R.

By the way, this material is also available in other languages:

- Italiano Understanding the map function
- Deutsch Understanding the map function
- Français Understanding the map function
- Español Understanding the map function
- Türk Understanding the map function
- Русский Understanding the map function
- Português Understanding the map function
- Polski Understanding the map function
- Nederlandse Understanding the map function
- 中文 Understanding the map function
- 한국어 Understanding the map function
- 日本語 Understanding the map function
- हिन्दी Understanding the map function

New York | 2022-12-03

Maybe there are another answers? What Understanding the map function exactly means?. Will get back tomorrow with feedback

Massachussetts | 2022-12-03

cartesian product is always a bit confusing 😭 Understanding the map function is not the only problem I encountered. Checked yesterday, it works!

California | 2022-12-03

I was preparing for my coding interview, thanks for clarifying this - Understanding the map function in Python is not the simplest one. I am just not quite sure it is the best method