Sobes.tech
Intern — Middle

Generator that mimics the behavior of the filter function

livecode

Task condition

Create a generator that reproduces the work of the built-in filter function, sequentially returning elements from the given iterable object for which the user-defined predicate function returns true.

Example 1: Input: gen = my_filter(lambda x: x % 2 == 0, [1, 2, 3, 4]) Output: [2, 4]