FUNCTIONAL PROGRAMMING IN PYTHON: THE MAP() FUNCTION
This section contains code samples that show you how to use the map() function, some of which involve lambda expressions that were discussed in the previous section. A subsequent section illustrates how to use the filter() function and also how to combine the filter() and map() functions in Python.
Listing 3.14 displays the contents of map1.py that illustrates how to use the Python map() function.
Listing 3.14: map1.py
def remainder(num):
  return num % 4
numbers = [-10, 11, -20, 55, 100, 201]
print("numbers:",numbers)
print()
iterator = map(remainder, numbers)
# option #1:
print("Mapped results: #1:")
print(list(iterator))
print()
# option #2:
iterator = map(remainder, numbers)
print("Mapped results: #2:")
for iter in iterator:
  print("value:",iter)
Listing 3.14 starts with the Python function remainder() that returns the integer remainder of dividing an integer...