Menu
Coddy logo textTech

filter

Lesson 5 of 9 in Coddy's Python Lambda Functions course.

Introducing filter built-in function,

filter(function, iterable)

The filter() function selects elements from an iterable (list, tuple etc.) based on the output of a function.

The function is applied to each element of the iterable and if it returns True, the element is selected by the filter() function.

The filter function returns iterable, which you can case to list or tuple easily.

Here is an example of using lambda with filter function,

lst = [1, 4, 2, 9, 13, 92, 6]
lmbd = lambda x : x % 2 == 0
only_even = list(filter(lmbd, lst))
print(only_even)  # [4, 2, 92, 6]
challenge icon

Challenge

Easy

Reminder! String are also iterables.

You are given a code, assign to function a lambda function that gets one argument and returns True if the argument is not a vowel.

Vowels are the characters - 'a', 'e', 'i', 'o', 'u'.

Try it yourself

iterable = input() # Don't change this line
function = ?

# Don't change below this line
no_vowels = filter(function, iterable)
print(''.join(list(no_vowels)))

All lessons in Python Lambda Functions