if w in word_to_index:
It does not work.
[[0. 0. 0. 0.]
[0. 0. 0. 0.]
[0. 0. 0. 0.]]
AssertionError Traceback (most recent call last)
in
20 print("\033[92mAll tests passed!")
21
—> 22 sentences_to_indices_test(sentences_to_indices)
AssertionError: Wrong values. Debug with the given examples
If I commented out line
if w in wprd_to_index, the test will passed. However I will get compile error("Funny’) during my submission
The “KeyError” message typically means that somewhere in your code, you’re not using the dictionary when you ought to.
I know I am not supposed to post my code here. But here is the problem area in def sentences_to_indices(X, word_to_index, max_len):
…
for w in range(len(sentence_words)):
# if w exists in the word_to_index dictionary
if w in word_to_index:
How to implement “#if w exists in the word_to_index dictionary”
I think I am making the mistake. But how to do “if w exists in the word_to_index dictionary” correctly?
for w in range(len(sentence_words)):
That’s not correct. You want to iterate through the “sentence_words”, not the whole range of integer length values.
Then you use “if w in word_to_index:” The if-statement will check every entry in the word_to_index dictionary, and if the word in ‘w’ is in the dictionary, execution will pass to the if-clause.
In the if-clause, you look up the word ‘w’ in the dictionary, and assign it to the correct location in X_indices.
I am also facing the same problem could anyone
please help me
Hi @KIRAN346 ,
The problem may seem the same, but it could be different. You have read the discussions here and still not able to solve your problem, then it indicates your problem may be different. The best thing to do is to post your query, tell us what your problem is, where it has gone wrong together with the error trace log, so that we have the information to help you solve your problem.
Hi @Bharadwajsegu ,
Although your code may have passed all the testcases, but they are there to give some confidence of your code. If you are getting error from the auto grader, then there must be some problem in your coding. This thread has been discussing the KeyError(‘funny’) issue. Is any of the information here helpful? If not, let’s know how we could help.
Hi @Kin Cheung Sir,
Thank you for sending Thread, that was discussing the KeyError(‘funny’) issue.
I resolved it from the discussions.
Thank you
Segu Sai Bharadwaj
How did you solve it? Kindly tell me the process. I did follow the above mention things In sentences_to_indices() fn, but none of them worked out
Hi,
Just go through this Document to get the answer for the Exercise of sentences_to_indices()
With Regards,
Segu Sai Bharadwaj
{mentor edit: document removed - does not support the course Honor Code}
Hey how? still didnt help
check the document I sent
Do not post the solutions to the programming assignments. That breaks the course Honor Code.
Life saving comment, thanks a lot TMosh
I need help. Can anybody help me out with this error my code is running properly but its still showing this error after submitting my assignment.
Cell #21. Can’t compile the student’s code. Error: KeyError(‘funny’,)
Hi @Ateeq_Ur_Rehman,
It is likely that your code is not using the dictionary provided. So please check. You might find your answer by reading through this thread.
Hey! I have this as welll
Can you help me solve it?