filter

filter(function, iterable)

Constructs an iterator (built-in).

functionfunction that tests if elements of an iterable return true or false
If None, the function defaults to Identity function - which returns false if any elements are false
iterableiterable which is to be filtered, could be sets, lists, tuples, or containers of any iterators

REMARKS
* This is a built-in function.
* Construct an iterator from those elements of iterable for which function is true. iterable may be either a sequence, a container which supports iteration, or an iterator. If function is None, the identity function is assumed, that is, all elements of iterable that are false are removed.
* Note that filter(function, iterable) is equivalent to the generator expression (item for item in iterable if function(item)) if function is not None and (item for item in iterable if item) if function is None.
* For the Official documentation refer to python.org

# list of alphabets 
alphabets = ['a', 'b', 'd', 'e', 'i', 'j', 'o']

# function that filters vowels
def filterVowels(alphabet):
vowels = ['a', 'e', 'i', 'o', 'u']

if(alphabet in vowels):
return True
else:
return False

filteredVowels = filter(filterVowels, alphabets)

print('The filtered vowels are:')
for vowel in filteredVowels:
print(vowel)

© 2026 Better Solutions Limited. All Rights Reserved. © 2026 Better Solutions Limited Top