Implement function build_dictionary(words) that returns a dictionary. The words parameter is a list of strings. Each word in the words parameter will be counted and you will build your dictionary around the frequency count. Each key of your dictionary will be the word in your list of strings and the corresponding value is an integer indicating the word’s frequency. Assume input is always valid. ‘Blue’ and ‘blue’ should be counted as the same word.
[You may use lower() ONLY and no other built-in function or method]
Examples:
words = [“blue”, “blue”, “red”, “yellow”, “yellow”, “brown”, “Blue”]
print(build_dictionary(words))
returns:
{‘blue’: 3, ‘red’:1, ‘yellow’:2, ‘brown’:1}
PLEASE GIVE IT A THUMBS UP, I SERIOUSLY NEED ONE, IF YOU NEED ANY MODIFICATION THEN LET ME KNOW, I WILL DO IT FOR YOU
def build_dictionary(words):
d = {}
count = 0
for i in words:
i = i.lower()
for j in words:
j = j.lower()
if i == j:
count += 1
d.update({i: count})
count = 0
return d
words = ["blue", "blue", "red", "yellow", "yellow", "brown", "Blue"]
print(build_dictionary(words))
Get Answers For Free
Most questions answered within 1 hours.