Programming Assignment: Emojify keyerror:'love;

I am constantly getting key errors (key error: love) when running the code, the only way past the error is by only trying to run the code if the key exists in the dictionary. but then this leads to counting errors.

any help would be appreciated.

Hi @saifalhaj

In the test case, you were given a sentence with the word ‘love’, but that word is not in the controlled word_to_vec_map which is designed for this testing your sentence_to_avg().
So you need to have a look at the code where it checks to see if a given word exists in the word_to_vec_map

i put in a checking function “if w in word_to_vec_map.keys():”

i get the Divide by count, not len(words) error.

is it because the words are skipped that the word count that Im using to divide the avg by is giving me errors?

Hi @saifalhaj

Does your code still increment “count” when the word is not in word_to_vec_map ?
if that is the case, then “avg” would not match the expected values listed in the assertion statement. Hence, the assertion is triggered.

that was it i had the count initialization in the wrong place in the loop so it would remain 0.


all the tests passed but when i submit i still get a 0/100 along with a

Cell #22. Can’t compile the student’s code. Error: KeyError(‘funny’,)


Hi @saifalhaj ,

This is a problem that a lot of student come across. You may find this thread might help.