Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Pedantic solution in Clear category for Stressful Subject by kkkkk
import re, string
def is_stressful(subj):
"""Recognise stressful subject line in email."""
# All letters uppercase?
if subj.isupper():
return True
# Ends with three exclamation marks?
if subj[-3:] == '!!!':
return True
# Contains any of these words in any case and with duplicate
# letters: help, asap, urgent?
# To check, first make letters lowercase and remove duplicates.
lc_subj = re.sub(r'([a-z])\1+', r'\1', subj.lower())
# Then remove punctuations inserted between letters.
trans_table = str.maketrans({key: None for key in string.punctuation})
ascii_subj = lc_subj.translate(trans_table)
# Now search for matches on 'red' words.
for word in ['help', 'asap', 'urgent']:
if word in ascii_subj:
return True
return False
Sept. 1, 2019