Friday, March 2, 2018

filter() in python

filter method filter out the iterable with the help of a given function and return the result in the form of a iter(list,set).

Basic Syntax :- filte(func,iter)


Example :-
a = [1,2,3,4,5]
c = list(filter(lambda x : x%2==0 ,a))
print(c)

It filter out the all those elements that are divisble by 2 from the above iterable a.
Hence  the output will be [2,4]

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...