Last active
February 3, 2025 15:44
-
-
Save Diapolo10/d3542552334978654f888f4e9fce71dc to your computer and use it in GitHub Desktop.
Python filter-function implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from typing import Any, Callable, Generator, Iterable, T | |
def my_filter(func: Callable[[T], Any], iterable: Iterable[T]) -> Generator[T, None, None]: | |
"""Yields all values from the iterable for which the function returns a truthful value""" | |
for value in iterable: | |
if func(value): | |
yield value |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment