The beauty of typed Python
Here’s an example of typed Python.
import itertools
from typing import Callable, Iterable, List, Tuple, TypeVar
A = TypeVar('A')
B = TypeVar('B')
def groupby_eager(iterable: Iterable[A],
key: Callable[[A], B]) -> List[Tuple[B, List[A]]]:
groups = itertools.groupby(sorted(iterable, key=key), key=key)
return [
(group_name, list(group))
for group_name, group in groups
]