Map
Explore how to use Python's map function to apply transformations to iterables efficiently. Understand lazy evaluation with map, handling single and multiple argument functions, and how to work with iterators returned by map for processing sequences.
We'll cover the following...
map function
The map function applies a supplied function to a set of arguments. It returns an iterator to access the results.
map with one parameter
In this example, we will use map with a user-defined function, square, that takes one parameter.
The map function applies square to each element in a, returning the squared values via an iterator. On line 7, we convert m to a list and print it.
Lazy evaluation
This is perhaps a good time to revisit the idea of lazy evaluation. All the functions described so far use lazy evaluation. We will illustrate this by ...