UNQ_C10 GRADED FUNCTION: get_corrections - Wrong output types and values

I got stuck here in “Test your function” with the following output (none of the already published tips seemed to help) >>

entered word = dys
suggestions = [‘dye’, ‘days’]
entered word = satr
suggestions = [‘sat’, ‘star’]
entered word = san
suggestions = [‘tan’, ‘sun’, ‘man’, ‘sap’, ‘sat’, ‘saw’, ‘can’, ‘wan’, ‘fan’, ‘an’, ‘sang’, ‘say’, ‘sin’, ‘son’, ‘sad’]
Wrong output type.
Expected: 5.
Got: 15.
Wrong output values.
Expected: [(‘say’, 0.0019770955347483865), (‘can’, 0.0019211400007460738), (‘an’, 0.0017719252434065728), (‘man’, 0.0013242809713880702), (‘son’, 0.0007274219420300668)].
Got: [[‘sad’, 0.00026112582534412656], [‘son’, 0.0007274219420300668], [‘sin’, 0.00026112582534412656], [‘say’, 0.0019770955347483865], [‘sang’, 1.865184466743761e-05], [‘an’, 0.0017719252434065728], [‘fan’, 3.730368933487522e-05], [‘wan’, 1.865184466743761e-05], [‘can’, 0.0019211400007460738], [‘saw’, 0.0002797776700115641], [‘sat’, 5.595553400231283e-05], [‘sap’, 1.865184466743761e-05], [‘man’, 0.0013242809713880702], [‘sun’, 0.0002797776700115641], [‘tan’, 1.865184466743761e-05]].
7 Tests passed
2 Tests failed

Reading over and over the conditions I should check :slight_smile:

  • If the word is in the vocabulary, suggest the word.
  • Otherwise, if there are suggestions from edit_one_letter that are in the vocabulary, use those.
  • Otherwise, if there are suggestions from edit_two_letters that are in the vocabulary, use those.
  • Otherwise, suggest the input word.*

I did not understand the last one. Wasn’t the input word already tested at the first condition? Or do you mean the regular expression “word.*”? this was the only condition i did not include at my code.

And I didnt understand why the output types are wrong, I tried everything but returning the list n_best was the only one that worked.

Let’s try to answer your queries one by one, starting with the below one.

For answering this, let me just state the motive behind the get_corrections function here. For a given word, we use the function to suggest corrections for it. Now, in Step-1, if the word is already in the vocabulary, it means that the word is correct, and it should be our first recommendation. However, if the word is not in the vocab, it means that the word is most probably incorrect, and hence, it should be our last recommendation. This is what Step-4 is about. Note that the order of recommendations is very important in this.

As for this, you might very well know that sometimes what the error statements indicate might not be the actual error. In your case, the number of returned suggestions is 15, whereas, you were only supposed to return the top n suggestions, and for this test-case n = 5. I believe you have simply returned all the suggestions. Note the Step-3 as mentioned in the markdown.

Step 3 : Select the n best suggestions. There may be fewer than n.

Let me know if this helps.


Thank you for this. Exactly what was needed to address the problem - a reminder that not all matches are required.