Skip to content

Week1 Assignment # UNQ_C10 GRADED FUNCTION #3

Open
@SajjadPSavoji

Description

@SajjadPSavoji

December 2022, I had to change the following function to pass all test cases

`# 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    
suggestions = list((word in vocab and word) or edit_one_letter(word).intersection(vocab) or edit_two_letters(word).intersection(vocab))
n_best = [[s,probs[s]] for s in list(reversed(suggestions))]
n_best = sorted(n_best, key=lambda x: x[1])[::-1][:n]
### END CODE HERE ###

if verbose: print("entered word = ", word, "\nsuggestions = ", suggestions)

return n_best`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions