Skip to content

Instantly share code, notes, and snippets.

@joan0fsnark
Created September 6, 2021 20:51
Show Gist options
  • Save joan0fsnark/5d538eb8cbc257ab4bd380adb839b03d to your computer and use it in GitHub Desktop.
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.
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