Last active
July 21, 2020 08:25
-
-
Save raeq/618f9afe5709d02e1f6f9dfff45e148a to your computer and use it in GitHub Desktop.
Check to See if a String Contains a Character Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string | |
def has_character_classes(input_string: str) -> tuple: | |
has_uppercase = False | |
has_lowercase = False | |
has_digits = False | |
has_whitespace = False | |
set_chars: set = {input_string} | |
for c in set_chars: | |
if c in string.ascii_uppercase and not has_uppercase: | |
has_uppercase = True | |
return (has_uppercase, has_lowercase, has_digits, has_whitespace) | |
u, l, d, w = has_character_classes("ALLUPPER") | |
assert () == u == True and l == False and d == False and w == False | |
u, l, d, w = has_character_classes("alllower") | |
assert () == u == False and l == True and d == False and w == False | |
u, l, d, w = has_character_classes(" ") | |
assert () == u == False and l == False and d == False and w == True | |
u, l, d, w = has_character_classes("UPPER01238") | |
assert () == u == True and l == False and d == True and w == False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment