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.

Revisions

  1. MikeLing revised this gist Mar 5, 2019. 1 changed file with 10 additions and 2 deletions.
    12 changes: 10 additions & 2 deletions question1.py
    Original file line number Diff line number Diff line change
    @@ -22,8 +22,15 @@ def is_stressful(subj):
    return True

    # check if it end up with exclamation marks.
    trace_back = subj.split('!')[-1]
    if trace_back.count('!') >= 2:
    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.
    @@ -36,4 +43,5 @@ def is_stressful(subj):

    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!"))
  2. MikeLing revised this gist Mar 5, 2019. 1 changed file with 4 additions and 9 deletions.
    13 changes: 4 additions & 9 deletions question1.py
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,8 @@ def is_stressful(subj):
    return True

    # check if it end up with exclamation marks.
    if subj.count('!') >= 3:
    trace_back = subj.split('!')[-1]
    if trace_back.count('!') >= 2:
    return True

    # check if it has red words.
    @@ -34,11 +35,5 @@ def is_stressful(subj):
    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 "))
    print (is_stressful("We need you A.S.A.P.!!"))
    print (is_stressful("Heeeeeeey !!!!! I'm having so much fun!"))
  3. MikeLing revised this gist Mar 5, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion question1.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    from collections import OrderedDict


    RED_WORDS = ['help', 'asap', 'urgent']
    RED_WORDS = ['help', 'asp', 'urgent']

    def check_red_words(word):
    # deal with the word
  4. MikeLing revised this gist Mar 5, 2019. 1 changed file with 9 additions and 9 deletions.
    18 changes: 9 additions & 9 deletions question1.py
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ def check_red_words(word):
    return True if lower_word in RED_WORDS else False


    def if_stressful(subj):
    def is_stressful(subj):
    # check if all the letters are uppercase.
    if subj.isupper():
    return True
    @@ -34,11 +34,11 @@ def if_stressful(subj):
    return False

    if __name__ == "__main__":
    print (if_stressful("It's stressful !!!"))
    print (if_stressful("STRESSFUL TITLE"))
    print (if_stressful("STRESSFUL TITLE !!!!!"))
    print (if_stressful("STRESSFUL TITLE !!"))
    print (if_stressful("HELLLLLLLLLLP"))
    print (if_stressful("HEEELLLLLL-LL-L-LP"))
    print (if_stressful("help"))
    print (if_stressful("It's not "))
    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 "))
  5. MikeLing created this gist Mar 5, 2019.
    44 changes: 44 additions & 0 deletions question1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    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 if_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 (if_stressful("It's stressful !!!"))
    print (if_stressful("STRESSFUL TITLE"))
    print (if_stressful("STRESSFUL TITLE !!!!!"))
    print (if_stressful("STRESSFUL TITLE !!"))
    print (if_stressful("HELLLLLLLLLLP"))
    print (if_stressful("HEEELLLLLL-LL-L-LP"))
    print (if_stressful("help"))
    print (if_stressful("It's not "))