def count_whitespace_prefix(string):
    """return the number of spaces at the beginning of the given string"""
    for i, ch in enumerate(string):
        if ch != ' ':
            return i
    return len(string)