Course Content
What is Python?
Introduction of Python and Its setup
0/2
Control Statement
Control statements are used to control the flow of execution depending upon the specified condition/logic.
0/4
File Handling
File handling is an important component of any application. Python has multiple functions for creating, reading, updating, and deleting files.
0/2
Examples
Following are the examples of python scripts to try hands-on, you are ready to start your python journey.
0/7
Python
About Lesson

Overview

The map()filter() and reduce() functions bring a bit of functional programming to Python. All three of these are convenience functions that can be replaced with List comprehensions or loops but provide a more elegant and short-hand approach to some problems

map() function

The map() function iterates through all items in the given iterable and executes the functions we passed as an argument on each of them.

Syntax

map(function, iterable(s))

Example

def starts_with_A(s):
	return s[0] == "A"

fruit = ["Apple", "Banana", "Pear", "Apricot", "Orange"]

map_object = map(starts_with_A, fruit)
print(list(map_object))

Output:

[True, False, False, True, False]

As we can see, we ended up with a new list where the function starts_with_A() was evaluated for each of the elements in the list fruit. The results of this function were added to the list sequentially.

The same can be done by the lambda function

fruit = ["Apple", "Banana", "Pear", "Apricot", "Orange"]
map_object = map(lambda s : s[0] == "A", fruit)
print(list(map_object))