The filter is a built-in function that takes a function and an iterable as arguments and returns a new iterable containing only the elements for which the function returns True.
filter(function, iterable)
It can be used to replace “for” loops that are used to filter out elements from an iterable. Here’s an example: