Python Basic Calculate word length Create a function that returns a dictionary with word lengthsand keys. Use
Question:
Python Basic
Calculate word length
Create a function that returns a dictionary with word lengthsand “keys”. Use a loop to evaluate each word separately usingthe len function. Forexample, len("something") would return 9. Initialize adictionary wl that is the same length as the list ofwords passed to your function and fill the dictionary with thenumber of characters in each word. Use the actual words as the keysfor the dictionary
def word_length(words):
# initialize a dictionary that will hold the
# word length information
# recall that python doesn't have named vectors
# so I'm using a dictionary instead and using
# another loop to create it
wl = {w: 0 for w in words}
# replace with your code
# return the dictionary of word lengths
return wl
word_length(["mouse", "king"]) # should return 5 and 4 in adictionary
word_length(["tax", "house", "purple"]) # should return 3, 5,and 6 in a dictionary
Database System Concepts
ISBN: 9780078022159
7th Edition
Authors: Abraham Silberschatz, Henry F. Korth, S. Sudarshan