Skip to content

Instantly share code, notes, and snippets.

@benawad
Created October 31, 2014 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benawad/30b4f7503f1f7bcdeb7b to your computer and use it in GitHub Desktop.
Save benawad/30b4f7503f1f7bcdeb7b to your computer and use it in GitHub Desktop.
def convert_numbers(s):
try:
return int(s)
except ValueError:
return None
def scan(sentence):
words = sentence.split()
sentence = []
for word in words:
word_tuple = ('error', word)
num = convert_numbers(word)
if (num != None):
word_tuple = ('number', num)
lc_word = word.lower()
if (lc_word == 'north' or lc_word == 'south' or lc_word == 'east' or lc_word == 'west' or lc_word == 'down' or lc_word == 'up' or lc_word == 'left' or lc_word == 'right' or lc_word == 'right'):
word_tuple = ('direction', word)
if (lc_word == 'go' or lc_word == 'stop' or lc_word == 'kill' or lc_word == 'eat'):
word_tuple = ('verb', word)
if (lc_word == 'the' or lc_word == 'in' or lc_word == 'of' or lc_word == 'from' or lc_word == 'at' or lc_word == 'it'):
word_tuple = ('stop', word)
if (lc_word == 'door' or lc_word == 'bear' or lc_word == 'princess' or lc_word == 'cabinet'):
word_tuple = ('noun', word)
sentence.append(word_tuple)
return sentence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment