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: 
Using a standard python dictionary you can make use of [**get**(key[, *default*])](https://docs.python.org/3/library/stdtypes.html#dict.get) to deal with the case when the key you want to increment does not exist in the dictionary.

> 
> [**get**(key[, *default*])](https://docs.python.org/3/library/stdtypes.html#dict.get)
> 
> 
> Return the value for *key* if *key* is in the dictionary, else *default*. If
>  *default* is not given, it defaults to `None`, so that this method never
>  raises a [KeyError](https://docs.python.org/3/library/exceptions.html#KeyError.).
> 
> 
> 

```
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"]
}

counts = {}
for year in food:
    for item in food[year]:
        counts[item] = counts.get(item, 0) + 1

print(counts)

```

**Output:**

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

```
It helps you:

```
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 ={} #dictionary for the counts
for word1 in Food.values():
    for word in word1:
        if word not in words_freq:

            words_freq[word] =1
        else:

            words_freq[word] +=1

print (words_freq)

```