Last active
March 5, 2019 06:33
-
-
Save MikeLing/5c4dc1a0a5b609d2950fe6bc8f8a5ff2 to your computer and use it in GitHub Desktop.
question from sun
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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