Create a function that takes in a list of words and returns a dictionary with...

This technical problem involves creating a function that takes in a list of words and returns a dictionary with the words as the keys and the number of times the word appears in the list as the values .

Problem

Create a function that takes in a list of words and returns a dictionary with the words as the keys and the number of times the word appears in the list as the values.
Example input:
['a', 'b', 'a', 'c', 'b']
Example output:
{'a': 2, 'b': 2, 'c': 1}

Solution

This solution is in Python. Our A.I. can create solutions in multiple languages.
by elrichendelgart
def word_count(words):
    word_dict = {}
    for word in words:
        if word in word_dict:
            word_dict[word] += 1
        else:
            word_dict[word] = 1
    return word_dict

print(word_count(['a', 'b', 'a', 'c', 'b']))

A.I. Evaluation of the Solution

This solution is complete and solves the problem. The approach is straightforward and easy to follow.

Evaluated at: 2022-11-10 00:16:02