Created
September 6, 2021 20:51
-
-
Save joan0fsnark/5d538eb8cbc257ab4bd380adb839b03d to your computer and use it in GitHub Desktop.
The function takes in a list of strings named 'words' as a parameter and return a dictionary of key/value pairs where every key is a word in words and every value is the length of that word.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def word_length_dictionary(words): | |
dict = {} | |
for word in words: | |
dict[word] = len(word) | |
return dict | |
# Uncomment these function calls to test your function: | |
print(word_length_dictionary(["apple", "dog", "cat"])) | |
# should print {"apple":5, "dog": 3, "cat":3} | |
print(word_length_dictionary(["a", ""])) | |
# should print {"a": 1, "": 0} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment