Type hints
Hints describe the shapes of values. The ones you will use most:
list[int],dict[str, int],set[str],tuple[int, str]for a fixed pair,tuple[int, ...]for any length.int | Nonefor "an int, or nothing". Older code writesOptional[int].Callable[[int, int], bool]for a function taking two ints and returning a bool. Import it fromtypingorcollections.abc.Anywhen you really can't say.
Python ignores hints at run time. The program shows that: passing a string
where the hint says list[int] runs fine. Tools like mypy and your editor catch it
before it runs.
Why bother in an interview? A signature like
def top_k(counts: dict[str, int], k: int) -> list[str] states the input and
output before you write the body. It shows clear thinking, and it settles
questions with the interviewer early.
Run it, then add hints to pair_up.