whats wrong with this code.
help me in solving this and i tried to use dictionary but not able to solve.
anyone solved using dictionaries post that code too.
direction = ('north', 'south', 'east')
verb = ('go', 'kill', 'eat')
stop = ('the', 'in', 'of')
noun = ('bear', 'princess')
error=('IAS','ASDFADFASDF')
number=(3,1234,91234)
def convert_number(s):
try:
return int(s)
except ValueError:
return None
def scan(sentence):
words = sentence.split()
empt=[]
for word in words:
if word in direction:
empt.append('direction', word)
return empt
elif word in verbs:
empt.append('verb', word)
return empt
elif word in stop:
empt.append('stop', word)
print empt
elif word in nouns:
empt.append('noun', word)
print empt
elif convert_number(word) in number:
empt.append('number', convert_number(word))
return empt
else:
return('error', word)