Exercise 48 nosetests error

if i run nosetests on lexicon_tests.py it shows error
Capturesns
but if i manually enter the arguments in scan() of lexicon.py it works well.
Any reason???
here is lexicon.py


def scan(sentence):
list1 =[[‘north’, ‘south’, ‘east’, ‘west’],
[‘go’, ‘kill’, ‘eat’],
[‘the’, ‘in’, ‘of’],
[‘door’, ‘bear’, ‘princess’, ‘cabinet’]]
words = sentence.split()
result = []
for word in words:
if word in list1[0]:
result.append((‘direction’, word))
elif word in list1[1]:
result.append((‘verb’, word))
elif word in list1[2]:
result.append((‘stop’, word))
elif word in list1[3]:
result.append((‘noun’, word))
else:
try:
ineger = int(word)
result.append((‘number’, word))
except:
result.append((‘error’, word))
print(result)


Capture

Iirc this was a pivotal moment for my learning when I hit it. Your code is appending to result then printing it.

But print and return are not the same. Your assertion is against the result output but you are only printing it, not returning it. So the test is correct by comparing your string with ‘None’ (as this is what print returns).

Try a return statement for result and compare that.

1 Like

Thank you…