Created
December 20, 2017 22:19
-
-
Save Coldsun1/e70283a01361d25304c0bb11d4b37679 to your computer and use it in GitHub Desktop.
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
def scan(sentence): | |
sentence = sentence.lower() | |
list_of_tuples = [] | |
words = sentence.split() | |
for word in words: | |
word_tuple = scan_word(word) | |
list_of_tuples.append(word_tuple) | |
return list_of_tuples | |
def scan_word(word): | |
direction_words = ['north', 'south', 'east', 'west', 'down', 'up', 'right', 'back'] | |
verb_words = ['go', 'stop', 'kill', 'eat'] | |
stop_words = ['the', 'in', 'of', 'from', 'at', 'it', 'to'] | |
noun_words = ['door', 'bear', 'princess', 'cabinet'] | |
if word in direction_words: | |
return ('direction', word) | |
elif word in verb_words: | |
return ('verb', word) | |
elif word in stop_words: | |
return ('stop', word) | |
elif word in noun_words: | |
return ('noun', word) | |
elif is_number(word): | |
return ('number', int(word)) | |
else: | |
return ('error', word) | |
def is_number(s): | |
try: | |
number = int(s) | |
return True | |
except ValueError: | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment