Failed testcase for w1_unittest.test_get_corrections(get_corrections, probs, vocab)

Why 1 failed testcase for w1_unittest.test_get_corrections(get_corrections, probs, vocab) ?

Wrong output values.
	Expected: [('say', 0.0019770955347483865), ('can', 0.0019211400007460738), ('an', 0.0017719252434065728), ('man', 0.0013242809713880702), ('son', 0.0007274219420300668)].
	Got: [['wan', 1.865184466743761e-05], ['sap', 1.865184466743761e-05], ['sad', 0.00026112582534412656], ['tan', 1.865184466743761e-05], ['can', 0.0019211400007460738]].
 8  Tests passed
 1  Tests failed
# UNIT TEST COMMENT: Candidate for Table Driven Tests
# UNQ_C10 GRADED FUNCTION: get_corrections
def get_corrections(word, probs, vocab, n=2, verbose = False):
    '''
    Input: 
        word: a user entered string to check for suggestions
        probs: a dictionary that maps each word to its probability in the corpus
        vocab: a set containing all the vocabulary
        n: number of possible word corrections you want returned in the dictionary
    Output: 
        n_best: a list of tuples with the most probable n corrected words and their probabilities.
    '''
    
    suggestions = []
    n_best = []
    
    ### START CODE HERE ###
    #Step 1: create suggestions as described above   
    sets_union = (edit_one_letter(word).intersection(vocab)).union(
          edit_two_letters(word).intersection(vocab))
    
    #suggestions = list(set(sets_union))
    suggestions = set(edit_one_letter(word).intersection(vocab) or edit_two_letters(word).intersection(vocab))
    
    #Step 2: determine probability of suggestions
    
    #Step 3: Get all your best words and return the most probable top n_suggested words as n_best
    
    n_best = [[s,probs[s]] for s in list(reversed(list(suggestions)))]
    n_best = n_best[:n]
    
    ### END CODE HERE ###
    
    if verbose: print("entered word = ", word, "\nsuggestions = ", suggestions)

    return n_best

Hi user342,

Note that the instructions read as follows:

Step 1: Generate suggestions for a supplied word: You’ll use the edit functions you have developed. The ‘suggestion algorithm’ should follow this logic:

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.*
The idea is that words generated from fewer edits are more likely than words with more edits.

You may want to use a Counter object, and also note that the function is supposed to return a list of tuples.

suggestions = set((word and (word in vocab)) or edit_one_letter(word).intersection(vocab) or edit_two_letters(word).intersection(vocab)) still does not help

Hi user342,

Note that 4 operations are required: ‘Otherwise, suggest the input word’. Good luck!