from typing import Tuple, Callable, Dict import run_tests def make_counter() -> Tuple[ Callable[ [ K ], None ], Dict[ K, int ] ]: ctr : Dict[ K, int ] = {} def fun( key: K ) -> None: ctr.setdefault( key, 0 ) ctr[ key ] += 1 return ( fun, ctr )