Important Notice:

Course Content
The Calendar Module
Library Function/Predefined Functions
0/4
Sys Module
Library Function/Predefined Functions
0/2
OS Module
Library Function/Predefined Functions
0/2
Functions in Python (Chapter-10) M3-R5
About Lesson

map() Function 

        The map() function executes a specified function for each item in a iterable. The item is sent to the function as parameter.

Syntax: map(function name ,iterable)

a=[5,10,15,20,25,30]

def myfun(a):

    if a%2==0:

        return True

    else:

        return False

def squ(a):

    return a*a

val=list(filter(myfun,a))

square=list(map(squ,val))

print(val)

print(square)

output

[10, 20, 30]

[100, 400, 900]

Without filter function

ages=[5,10,15,18,20,25,35]

sqr=list(map(lambda a:a*a,ages))

print(sqr)

Output

[25, 100, 225, 324, 400, 625, 1225]

 

Using lambda function

ages=[5,10,13,15,17,18,20,22,25]

adults=filter(lambda a:a>18,ages)

square=list(map(lambda a:a*a,adults))

print(square)

output

[400, 484, 625]

error: Content is protected !!