Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
itertools.groupby solution in Clear category for Stressful Subject by sudee
from itertools import groupby
def normalize_word(word):
"""
Returns the lowercase word without symbols and duplication
"""
clear_word = filter(str.isalpha, word.lower())
return ''.join(char for (char, _) in groupby(clear_word))
def is_stressful(subj):
"""
recognise stressful subject
"""
words = map(normalize_word, subj.split(' '))
has_red_word = any(word in ['help', 'asap', 'urgent'] for word in words)
return subj.isupper() or subj.endswith('!!!') or has_red_word
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert is_stressful("Hi") == False, "First"
assert is_stressful("I neeed HELP") == True, "Second"
assert is_stressful("HELP PLS") == True, "Shout"
assert is_stressful("plz!!!") == True, "!!!"
assert is_stressful("heeeelp") == True, "Duplication"
print('Done! Go Check it!')
Dec. 12, 2018