This is a part of a larger program. Here is what I am trying to do.
- Pass a sentence to the scan method.
- Have the sentence contain numbers.
- Split the sentence into it's different terms.
- append to a list a tuple, the first expression in the tuple being the type of thing that the word or sentence element fits into, the second being the word or number.
Here is what I am trying:
def scan(self, sentence):
self.term = []
for word in sentence.split():
if word in direction:
self.term.append(('direction', word))
elif word in verbs:
self.term.append(('verb', word))
elif word in stop:
self.term.append(('stop', word))
elif word in nouns:
self.term.append(('noun', word))
elif type(int(word)) == 'int':
self.term.append(('number', int(word)))
else:
self.term.append(('error', word))
return self.term
print lexicon.scan('12 1234')
This is a method in a class, the print statement is outside. The part I am concerned with and having trouble with is this:
elif type(int(word)) == int:
self.term.append(('number', int(word)))
It should work for any natural number [1, infinity)
Edit: I run into a problem when I try to scan('ASDFASDFASDF')