Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Readable solution with comments solution in Clear category for Stressful Subject by pavel.fasther
import itertools
RED_WORDS = ("help", "asap", "urgent", )
def is_stressful(text):
if text[-3:] == "!!!":
return True
# removed non-text chars
cleaned_text = "".join(list(filter(lambda x: x.isalpha(), text)))
# removed duplicates
cleaned_text = "".join(val for val, g in itertools.groupby(cleaned_text))
# Check upper
if all(map(lambda x: x.isupper(), cleaned_text)):
return True
# Check red words
for stress_word in RED_WORDS:
if stress_word in cleaned_text.lower():
return True
return False
Nov. 26, 2020
Comments: