Last active
October 21, 2022 17:03
-
-
Save johnw42/44ad2c244e500c19385e8f72f04a1a20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import takewhile | |
from typing import Iterable, Sequence, TypeVar | |
T = TypeVar("T") | |
def common_prefix(seqs: Iterable[Sequence[T]]) -> Iterable[T]: | |
"Returns the common prefix of a sequence of sequences." | |
return (c[0] for c in takewhile(lambda x: all(x[0] == y for y in x), zip(*seqs))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment