Question: . is_valid_word: This function takes as input a string and a dictionary. The dictionary has the same format as the one returned by the function

 . is_valid_word: This function takes as input a string and adictionary. The dictionary has the same format as the one returned by

. is_valid_word: This function takes as input a string and a dictionary. The dictionary has the same format as the one returned by the function create_scrabble_dict. This function returns true if the input string appears in the dictionary, false otherwise. For example, > > > w= ['aa', 'qi', 'za', 'cat', 'can', 'cow', 'dog', 'dad' , 'hippo', 'umami', 'uncle'] >>> d = create_scrabble_dict (w) >>> is_valid_word ( 'hippo ' , d) True >>> is_valid_word( 'zebra' , d) False >>> is_valid_word ('pear' , d) Falsedef create_scrabble_dict (words ) : d = {} word_dict = {} word_list = for word in words: # get length of the word key = len(word) # get first character of the word first_char = word[0] if key in d. keys ( ) : word_dict = d[key] else: word_dict = {} if first_char in word_dict. keys ( ) : word_list = word_dict [first_char] else: word_list = word_list . append (word) word_dict [first_char] = word_list d [key] = word_dict return d words = ["aa", "qi", "za", "cat", "can", "cow", "dog", "dad", "hippo", "umami", "uncle" ] d = create_scrabble_dict (words) # print(d)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!