Question: I am a first-time learner of python, I understand how to use word frequencies to count the number of each unique variable of a list, like this

```
sentence = ['hello', 'people', 'are', 'the', 'most', 'common', 'word', 'people', 'use', 'for', 'language ', 'learning']

words_freq ={} #dictionary for the counts
for word in sentence:
    if word not in words_freq:

        words_freq[word] =1
    else:

        words_freq[word] +=1

print (words_freq)

```

however, I wonder how could a word frequencies do on the dictionary by using a double for loop?

for example, I have a dictionary like this

```
Food = {
2015: ["Apple", "Milk", "Cookie", "Banana", "Orange" ],
2016: ["Potato", "Orange", "Chocolate", "Milk", "Mango"],
2017: ["Fish", "Potato", "Orange", "Mango", "Banana"],
2018: ["Beef", "Pork", "Fish", "Apple", "Cookie"],
2019: ["Pork", "Orange", "Apple", "Mango", "Chocolate"]
}

```

how to do a word frequencies/count and print something like this? Or store the highest value in list form ?
apple : 3
milk : 2
orange : 3
..
..
..

Answer: 
defaultdict would be pretty elegant for your use case
it create a default dictionary for a given type for int - the default value is 0 for int value, it enable you to write less code

<https://docs.python.org/3.3/library/collections.html#collections.defaultdict>

`from collections import defaultdict`

```
def get_freq(food_dict: dict) -> dict:
    freq = defaultdict(int)
    for year, lst in food_dict.items():
        for elem in lst:
            freq[elem] += 1
    return freq

```
Another way you could do this is to create a single list, and then count frequencies in that list:

```
foodList = []

#creates a single list
for idx, f in enumerate(Food):
    foodList = foodList + list(Food.values())[idx]

#makes a count in that list
words_freq ={}
for word in foodList:
    if word not in words_freq:
        words_freq[word] =1
    else:
        words_freq[word] +=1

```

which yields the correct answer:

```
{'Apple': 3, 'Milk': 2, 'Cookie': 2, 'Banana': 2, 'Orange': 4, 'Potato': 2, 'Chocolate': 2, 'Mango': 3, 'Fish': 2, 'Beef': 1, 'Pork': 2}

```