Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Generage Regexp strings from list, and just check all other requirements solution in Clear category for Stressful Subject by ipavel83
import re
REDWORDS = ['help', 'asap', 'urgent']
def findREDWORDInText(text, word):
def makeRegExp(word):
return ''.join([f'[{x.lower()}{x.upper()}]+\W*' for x in word])
return re.search(makeRegExp(word), text)
def is_stressful(subj):
if subj.isupper():
return True
if re.search(r'!{3,}$',subj): #ends with 3 or more of !
return True
for w in REDWORDS:
if findREDWORDInText(subj, w) != None:
return True
return False
if __name__ == '__main__':
#These "asserts" are only for self-checking and not necessarily for auto-testing
assert is_stressful("Hi") == False, "First"
assert is_stressful("I neeed HELP") == True, "Second"
assert is_stressful("I neeed A!S!a!P") == True, "asap"
assert is_stressful("I neeed A!S!Ba!P") == False, "asBap"
assert is_stressful("ALL UPPER!!234") == True, "UPPER"
assert is_stressful("ends with !!!") == True, "!!!"
assert is_stressful("ends with !!") == False, "!!"
print('Done! Go Check it!')
Dec. 1, 2019