def countwhile(predicate, iterable):
    """
    return count of leading characters that satisfy the predicate
    """
    count = 0
    for character in iterable:
        if predicate(character):
            count += 1
        else:
            break
    return count