2025-12-01

This commit is contained in:
2026-03-17 14:58:51 -06:00
parent 183e865f8b
commit 4b82b57113
6846 changed files with 954887 additions and 162606 deletions
@@ -0,0 +1,16 @@
from collections import defaultdict
from typing import Callable, Collection, Dict, List, TypeVar
__all__ = ["group_by"]
K = TypeVar("K")
T = TypeVar("T")
def group_by(items: Collection[T], key_fn: Callable[[T], K]) -> Dict[K, List[T]]:
"""Group an unsorted collection of items by a key derived via a function."""
result: Dict[K, List[T]] = defaultdict(list)
for item in items:
key = key_fn(item)
result[key].append(item)
return result