Question: Please make sure code runs correctly, ive posted this multiple times and usually code doesnt work and also what output should be is provided below
get previous words dicto Define the get_previous_words_dict function whiclh is passed a string of text as a parameter. The functin returns a dictionary with keys which are all the unique words from the text, and corresponding values which are lists of all the unique words in the text which come before the key word. Note that in each corresponding list of previous words, the same word should not appear more than once Notes: e the first word in the sentence will initially have the empty string as its previous word, you can assume that the text is all in lower case and contains no punctuation, ec each list of previous words must be sorted into ascending order, ee the testing code makes use of the print dict_in_key order (a_dict) which prints the dictionary pairs in sorted key order. For example, the following code: text 'a man we saw saw a saw. previous_words_dict- get_previous_words_dict (text) print dict in key order (previous words dict) print () text-'my favourite painting is the painting i dicd of my dog in that painting in my den previous_words dict -get_previous_words_dict (text) print dict in_key_order (previous_words_dict) prints: a,w'] man saw 'asaw' 'we' we: 'man'] den 'my did dog [ 'i') 'my' ] favourite 'my'1 i : ['painting
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
