String Validators

  • + 0 comments

    Nice concise solution! But, not an efficient one as you're looping through the string for every print.

    s = input()
    is_alpha = is_digit = is_lower = is_upper = False
    
    for char in s:
        if not is_alpha:
            is_alpha = char.isalpha()
    
        if char.isalpha():
            if not is_lower:
                is_lower = char.islower()
            if not char.islower() and not is_upper:
                is_upper = char.isupper()
        else:
            if not is_digit:
                is_digit = char.isdigit()
    
    print(is_alpha or is_digit)
    print(is_alpha)
    print(is_digit)
    print(is_lower)
    print(is_upper)