Skip to content

Instantly share code, notes, and snippets.

@MikeLing
Last active March 5, 2019 06:33
Show Gist options
  • Select an option

  • Save MikeLing/5c4dc1a0a5b609d2950fe6bc8f8a5ff2 to your computer and use it in GitHub Desktop.

Select an option

Save MikeLing/5c4dc1a0a5b609d2950fe6bc8f8a5ff2 to your computer and use it in GitHub Desktop.
question from sun
from collections import OrderedDict
RED_WORDS = ['help', 'asap', 'urgent']
def check_red_words(word):
# deal with the word
# remove_duplicate = "".join(OrderedDict.fromkeys(word))
temp = []
for i in word:
if i not in temp and i.isalpha():
temp.append(i)
remove_duplicate = ('').join(temp)
lower_word = remove_duplicate.lower()
return True if lower_word in RED_WORDS else False
def is_stressful(subj):
# check if all the letters are uppercase.
if subj.isupper():
return True
# check if it end up with exclamation marks.
if subj.count('!') >= 3:
return True
# check if it has red words.
split_string = subj.split()
for w in split_string:
if check_red_words(w):
return True
return False
if __name__ == "__main__":
print (is_stressful("It's stressful !!!"))
print (is_stressful("STRESSFUL TITLE"))
print (is_stressful("STRESSFUL TITLE !!!!!"))
print (is_stressful("STRESSFUL TITLE !!"))
print (is_stressful("HELLLLLLLLLLP"))
print (is_stressful("HEEELLLLLL-LL-L-LP"))
print (is_stressful("help"))
print (is_stressful("It's not "))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment