Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
somewhat clear solution in Clear category for Stressful Subject by furtadobb
""" A stressful subject line means that all letters are in uppercase, and/or ends by at least 3 exclamation marks,
and/or contains at least one of the following “red” words: "help", "asap", "urgent". Any of those "red" words can be
spelled in different ways - "HELP", "help", "HeLp", "H!E!L!P!", "H-E-L-P", even in a very loooong way
"HHHEEEEEEEEELLP," they just can't have any other letters interspersed between them. """
import re
import itertools
def is_stressful(subj):
"""
recognize stressful subject
"""
up = all(i.isupper() for i in re.findall(r'\w', subj))
marks = subj[-3:] == '!!!'
words = ''.join(c[0] for c in itertools.groupby(subj))
treated_words = any([i for i in ['help', 'asap', 'urgent'] if i in words.replace('!', '')
.replace('.', '').replace('-', '').lower()])
return up or marks or treated_words
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"
print('Done! Go Check it!')
Sept. 16, 2020