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

```
You don't need a double loop, but you can do something like this:

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

words_freq = {}
for year in food.keys():
    for fruit in food[year]:

        if fruit in words_freq.keys():
            words_freq[fruit] += 1
        else:
            words_freq[fruit] = 1

```