Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using regex but kind of rushed this one solution in Clear category for Stressful Subject by lucas.stonedrake
import re
def is_stressful(subj):
# is it all capitals
c1 = subj.isupper()
# does it end in !!!
c2 = subj[-3:] == '!!!'
# remove any non alphabetical chars and make lower case
subj = ''.join(re.findall('[a-z]', subj.lower()))
matcher = re.compile(r'(.)\1*')
# make a list of strings according to matcher
subj = [match.group() for match in matcher.finditer(subj)]
#join but remove any adjacent letters which are identical
subj = ''.join([w[0] for w in subj])
# are any of these words present?
c3 = any(w in subj for w in ['help', 'asap', 'urgent'])
return c1 or c2 or c3
if __name__ == '__main__':
#These "asserts" are only for self-checking and not necessarily for auto-testing
assert is_stressful("Hi") == False, "First"
assert is_stressful("I neeed HELP") == True, "Second"
print('Done! Go Check it!')
Nov. 18, 2020