Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
re.search solution in Clear category for Stressful Subject by MuxaJlbl4
import re
def is_stressful(subj):
undesireble_list = ["help", "asap", "urgent"]
# Check uppercase (letters only) and exclamations
if re.sub('[^A-Za-z]','', subj).isupper() == True or subj.endswith("!!!") == True:
return True
# Check undesireble words
for word in undesireble_list:
if re.search(word, subj, re.IGNORECASE):
return True
# Check undesireble words with anything between letters
# Create patterns
for word in undesireble_list:
i = 0
pattern = ""
while i < len(word)-1:
pattern += r'[' + word[i] + r']+[^A-Za-z]*'
i += 1
pattern += r'[' + word[-1] + r']+'
# Check undesireble words contains non letters between key letters
if re.search(pattern, subj, re.IGNORECASE): # pattern == r'[h]+[^A-Za-z]*[e]+[^A-Za-z]*[l]+[^A-Za-z]*[p]+'
return True
return False
Nov. 17, 2020
Comments: