Skip to content

Instantly share code, notes, and snippets.

@MikeLing
Last active March 5, 2019 06:33
Show Gist options
  • Save MikeLing/5c4dc1a0a5b609d2950fe6bc8f8a5ff2 to your computer and use it in GitHub Desktop.
Save MikeLing/5c4dc1a0a5b609d2950fe6bc8f8a5ff2 to your computer and use it in GitHub Desktop.
question from sun
from collections import OrderedDict
RED_WORDS = ['help', 'asp', '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.
reversed_words = subj[::-1]
counter = 0
for i in reversed_words:
if i == '!':
counter = counter + 1
else:
break
if counter >= 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("We need you A.S.A.P.!!"))
print (is_stressful("Where are you?!!!"))
print (is_stressful("Heeeeeeey !!!!! I'm having so much fun!"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment