Problem in ex48

what does mean this error

lexicon = {
	'north' 	:"direction",
	'south' 	:"direction",
	'east' 		:"direction",
	'west' 		:"direction",
	'down' 		:"direction",
	'up' 		:"direction",
	'left' 		:"direction",
	'right' 	:"direction",
	'back' 		:"direction",
	'go'		:"verbs",
	'stop'		:"verbs",
	'kill'		:"verbs",
	'eat'		:"verbs",
	'the' 	:"stopWords",
	'in' 	:"stopWords",
	'of' 	:"stopWords",
	'from'  :"stopWords",
	'at' 	:"stopWords",
	'it' 	:"stopWords",
	'door'      :"nouns",
	'bear'		:"nouns",
	'princess'		:"nouns",
	'cabinet'		:"nouns",
	'0'	:'number',
	'1'	:'number',
	'2'	:'number',
	'3'	:'number',
	'4'	:'number',
	'5'	:'number',
	'6'	:'number',
	'7'	:'number',
	'8'	:'number',
	'9'	:'number'
}

stuff = input("→❓→  ")
words = stuff.split()
 

def scan(key):
	# pass
	result  = []
	count = 0
	for i in key: 
		wordType = lexicon.get(i)
		pair = [(wordType, i)]
		result.append(pair)
		if wordType == 'direction':
		 	print(result[count])
		count = count + 1
scan(words)


There’s no return in your function so it implicitly returns None.

I don’t understand where I use return?

In your test you have this line:

assert lexicon.scan('north') == [('direction','north')]

That does three things:

  1. Call lexicon.scan with ‘north’
  2. Compare the return from the lexicon.scan function to the [(‘direction’,‘north’]) expected result.
  3. Use assert the raise an error when this isn’t true.

Most likely your lexicon.scan function isn’t returning properly, so you get a None value, and assert is telling you that None does not equal [(‘direction’,‘north’]).

1 Like