Skip to content

Instantly share code, notes, and snippets.

@Diapolo10
Last active March 18, 2021 15:12
Show Gist options
  • Save Diapolo10/1b17a31e4fed36d7dc8cffa27ef9446c to your computer and use it in GitHub Desktop.
Save Diapolo10/1b17a31e4fed36d7dc8cffa27ef9446c to your computer and use it in GitHub Desktop.
Python min-function example implementation
#!/usr/bin/env python3
from typing import Callable, Iterable, T
def my_min(iterable: Iterable[T], key: Callable[[T, ...], Any]=lambda x: x) -> T:
iterator = iter(iterable)
try:
lowest = key(next(iterator))
except StopIteration:
raise ValueError("Iterable is empty")
for value in iterator:
value = key(value)
if lowest > value:
lowest = value
return lowest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment