# A generic function over `list[T]` (a formal package of the list's), a list of tuples with a
# str in them, and CPython's case mappings and character classes beyond Latin-1 (D188). Its
# output is CPython's.
from verada import invariant


def first[T](xs: list[T], d: T) -> T:
    if len(xs) == 0:
        return d
    return xs[0]


def count_of[T](xs: list[T], wanted: T) -> int:
    n = 0
    for i in range(len(xs)):
        invariant(0 <= n <= i)
        if xs[i] == wanted:
            n += 1
    return n


def main() -> None:
    xs: list[int] = [4, 5, 4]
    words: list[str] = ["b", "a"]
    empty: list[str] = []
    print(first(xs, 0), first(words, "none"), first(empty, "none"), count_of(xs, 4))
    pairs: list[tuple[int, str]] = [(1, "one"), (2, "two")]
    for n, name in pairs:
        print(n, name.upper())
    s = "ωορλδ"
    print(s.upper(), s.isalpha(), "٣".isdigit(), "Ω".lower(), "ÉCOLE".lower(), "straße".upper())
    print("émile".capitalize(), "ΑΒΓ".swapcase(), "μ".upper())


if __name__ == "__main__":
    main()
