Skip to content

Instantly share code, notes, and snippets.

@Diapolo10
Last active February 3, 2025 15:44
Show Gist options
  • Save Diapolo10/d3542552334978654f888f4e9fce71dc to your computer and use it in GitHub Desktop.
Save Diapolo10/d3542552334978654f888f4e9fce71dc to your computer and use it in GitHub Desktop.
Python filter-function implementation
#!/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