String Validators

Sort by

recency

|

1963 Discussions

|

  • + 0 comments

    print(any(c.isalnum() for c in s)) print(any(c.isalpha() for c in s)) print(any(c.isdigit() for c in s)) print(any(c.islower() for c in s)) print(any(c.isupper() for c in s))

    any()-> its a builtin function and checks if any conditons are true , this function can be used in any iterables.

  • + 0 comments

    if name == 'main': s = input()

    has_alnum = bool()
    has_alpha = bool()
    has_digit = bool()
    has_lower = bool()
    has_upper = bool()
    
    for ch in s:
        if ch.isalnum(): has_alnum = True
        if ch.isalpha(): has_alpha = True
        if ch.isdigit(): has_digit = True
        if ch.islower(): has_lower = True
        if ch.isupper(): has_upper = True
    
    print(has_alnum)
    print(has_alpha)
    print(has_digit)
    print(has_lower)
    print(has_upper)
    
  • + 0 comments
    s = input()
    methods = ["isalnum","isalpha","isdigit","islower","isupper"]
    for method in methods:
        result = any(getattr(c,method)() for c in s)
        print(result)
    
  • + 0 comments
    if __name__ == '__main__':
        s = input()
        answer = []
        for _ in range(5):
            answer.append(False)
        for chr in s: 
            if chr.islower():
                answer[0] = answer[1] = answer[3] = True
            elif chr.isupper(): 
                answer[0] = answer[1] = answer[4] = True
            if chr.isdigit(): 
                answer[0] = answer[2] = True
            if False not in answer: 
                break
        for x in answer: 
            print(x)
    
  • + 0 comments
    def checker(s, values, validation):
        """ Populates a list 'values' with strings 'True' or 'False'  verifying 
        the string 's' by the function given by 'validation' """
    		
        for item in s:
            if validation(item):
                values.append('True')
            else:
                values.append('False')
        return values    
    
    def executor(s, values, validation):
        """ Clears the values list, applies the checker function 
        and returns the appropriate value """
    		
        values.clear()
        print(True if 'True' in checker(s, values, validation) else False)
    
    if __name__ == '__main__':
        s = input()
    
    values = []
    executor(s, values, str.isalnum)
    executor(s, values, str.isalpha)
    executor(s, values, str.isdigit)
    executor(s, values, str.islower)
    executor(s, values, str.isupper)