Была поставлена задача:
The function should recognises if a subject line is stressful. A stressful subject line means that all letters are 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»
is_stressful(«Hi») == False
is_stressful(«I neeed HELP») == True
Я решил таким образом:
def is_stressful(subj):
stress_symbol = "!!!"
stress_words = ["help", "asap", "urgent"]
removed_symbols = ";-,.!"
outdata = " "
if subj.isupper() or subj[-3:] == stress_symbol:
return True
subj = subj.lower()
for x in range(len(subj)):
if subj[x] == outdata[-1] or subj[x] in removed_symbols:
continue
else:
outdata += subj[x]
for x in outdata.split():
if x in stress_words:
return True
return False