Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
I borrowed some regex for this solution in Clear category for Stressful Subject by BootzenKatzen
import re # importing regular expressions even though I'm bad at it
def is_stressful(subj):
if subj.isupper(): # if the whole string is uppercase
return True # return true
if subj[-3:] == '!!!': # if the last three characters of the string are !
return True # return True
redwords = ('asap', 'help', 'urgent') # establishing a list of words to check for
subj = subj.lower() # making the string lowercase so the case doesn't matter
nopunct = re.sub(r'[^\w\s]', '', subj) # I googled how to remove punctuation with re
unstrung = re.sub(r'([a-z])\1+', r'\1', nopunct) # I googled how to remove repeated characters with re
for word in redwords: # for each of our red words
if word in unstrung: # check if they're in the lowercase, non stretched out string
return True # if they are, return True
return False # if nothing triggers True, return False
if __name__ == '__main__':
#These "asserts" are only for self-checking and not necessarily for auto-testing
print(is_stressful('UUUURGGGEEEEENT here'))
assert is_stressful("Hi") == False, "First"
assert is_stressful("I neeed HELP") == True, "Second"
print('Done! Go Check it!')
May 18, 2023
Comments: