Filter() function

0

Filter() function

  • We can use filter() function to filter values from the given sequence based on some condition.
  • Where function argument is responsible to perform conditional check   sequence can be list or tuple or string.
  • The filter() function is useful to filter out the elements of sequence depending on the result of a function. We should supply a function and a sequence to the filter() function.

Syntax

  • filter(function, sequence)

Q. Program to filter only even numbers from the list by using filter() function?  

  • Without lambda Function:

  • With lambda Function:


Post a Comment

0Comments
Post a Comment (0)