Friday, March 2, 2018

map() in python

The map() function applies a given function to each item of an iterable (list, tuple etc.) and returns a list of the results.

Basic Syntax :- map(func,iter)

Note :- we can provide more than one iterable in the map function.

Example :-  a = [1,2,3,4,5]
c =list(map(lambda x : x+1 ,a))
print(c)
The output is [2, 3, 4, 5, 6]

Example :- More than one iterable

a = [1,2,3,4,5]
b=[1,2,3,4,5]
c =list(map(lambda x,y : x+y ,a,b))
print(c)

#The output is [2, 4, 6, 8, 10]

No comments:

Post a Comment

Hadoop - What is a Job in Hadoop ?

In the field of computer science , a job just means a piece of program and the same rule applies to the Hadoop ecosystem as wel...