Here’s a succinct definition of a first() function for Python:

# Licensed under the LGPLv3
# © 2022 Alex DeLorenzo
from typing import Iterable, TypeVar


T = TypeVar('T')
U = TypeVar('U')


def first(iterable: Iterable[T], default: U | None = None) -> T | U | None:
  iterable = iter(iterable)
  return next(iterable, default)