def hashdigit(cpf, position):  # type: (str, int) -> int
    """
    Will compute the given `position` checksum digit for the `cpf`
    input. The input needs to contain all elements previous to
    `position` else computation will yield the wrong result.
    """
    val = sum(int(digit) * weight for digit, weight in zip(cpf, range(position, 1, -1))) % 11
    return 0 if val < 2 else 11 - val