String Validators

Sort by

recency

|

1965 Discussions

|

  • + 0 comments

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

    checks = [
        lambda s: any(c.isalnum() for c in s),
        lambda s: any(c.isalpha() for c in s),
        lambda s: any(c.isdigit() for c in s),
        lambda s: any(c.islower() for c in s),
        lambda s: any(c.isupper() for c in s)
    ]
    
    for func in checks:
        print(func(s))
    
  • + 0 comments

    using getattr

    s = input()
    method_name = ['isalnum', 'isalpha', 'isdigit', 'islower', 'isupper']
    
    for name in method_name:
    		print(any(getattr(c, name)() for c in s))
    
  • + 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)