69.7k views
2 votes
You are given some words. Some of them may repeat. For each word, output its number of occurrences. The output order should correspond with the input order of appearance of the word. See the sample input/output for clarification.

1 Answer

0 votes

Final answer:

To count the number of occurrences of words in a list, create a dictionary, iterate through the list, and increment the count for each word.

Step-by-step explanation:

The question you provided seems to be incomplete and unrelated to the topic of counting the number of occurrences of words. However, if your question is about counting the number of occurrences of words, here is how you can solve it.

  1. Create an empty dictionary to store the words and their occurrences.
  2. Iterate through each word in the given list.
  3. If the word is already in the dictionary, increment its count by 1.
  4. If the word is not in the dictionary, add it as a new key with a count of 1.
  5. Finally, iterate through the dictionary and print each word along with its count.

For example, let's say you have the list ['apple', 'banana', 'apple', 'cherry', 'banana']. The dictionary would look like {'apple': 2, 'banana': 2, 'cherry': 1}. So, the output would be:

apple: 2
banana: 2
cherry: 1

User KaseOga
by
7.6k points