Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Stressful Subject by vurutana
def is_stressful(subj):
import string
# Algorithm of the function.
# 1. Test subj if ends by 3 exclamation marks.
# 2. Test subj if all letters are UPPERCASED.
# 3. Convert all subj letters to lowercased and split by " ".
# 4. Delete all punctuations and digits and remove all duplicates.
# 5. Test substrings of subj if 'help', 'asap', 'urgent' occured.
# 1. Test subj if ends by 3 exclamation marks.
if subj.endswith("!!!") == True: return True
# 2. Test subj if all letters are UPPERCASED.
if subj.isupper() == True: return True
# 3. Convert all subj letters to lowercased and split by " ".
lower_subj = subj.lower().split()
# 4. Delete all punctuations and digits.
xi = 0
xj = 0
word = ""
last_added_letter = None
while xi < len(lower_subj):
while xj < len(lower_subj[xi]):
if ((lower_subj[xi][xj] not in string.punctuation and
lower_subj[xi][xj] not in string.digits and
lower_subj[xi][xj] != last_added_letter)):
word += lower_subj[xi][xj]
last_added_letter = lower_subj[xi][xj]
xj += 1
lower_subj[xi] = word
word = ""
last_added_letter = None
xj = 0
xi += 1
# 5. #Test substrings of subj if 'help', 'asap', 'urgent' occured.
for i in lower_subj:
if 'help' in i or 'asap' in i or 'urgent' in i:
return True
return False
Oct. 12, 2018