Question: > 
> Write a program that reads a sentence. The program then prints a table of word frequencies. The words are in alphabetical order with the number of times each word occurs. The words are case insensitive. The program has a word\_frequencies(words) function that takes string input. It builds a word frequency dictionary from the input words string and returns the dictionary of word frequencies.
> 
> 
> 

```
def word_frequencies(words):
# Implement the word_frequencies function.  The words function parameter is a string.
# Your solution here
    freq = {}
    for word in words:
        freq[word] = words.count(word)
    return freq

# The main program.  Do not change it.
if __name__ == '__main__':
    words = input("Enter a sentence: ")
    your_dictionary = word_frequencies(words)
    sorted_keys = sorted(your_dictionary.keys())
    for key in sorted_keys:
        print(key + ': ' + str(your_dictionary[key]))

```

This is the code I have but it's returning the frequencies for letters and spaces, not words when entering in ZyBooks now zyBooks later zyBooks forever

```
 : 5
B: 3
Z: 1
a: 1
e: 3
f: 1
k: 3
l: 1
n: 1
o: 8
r: 3
s: 3
t: 1
v: 1
w: 1
y: 3
z: 2

```

Answer: 
By using [`collections.Counter`](https://docs.python.org/3/library/collections.html#collections.Counter)

```
from collections import Counter

def word_frequencies(words):

    return  Counter(words.split(" "))

if __name__ == '__main__':
    words = input("Enter a sentence: ")
    your_dictionary = word_frequencies(words)
    sorted_keys = sorted(your_dictionary.keys())
    for key in sorted_keys:
        print(key + ': ' + str(your_dictionary[key]))

```

Output:

```
Enter a sentence: hi hi hi hello hello df
df: 1
hello: 2
hi: 3

```
You just need to `split()` the input into list of words. And you can also use dict comprehension:

```
def word_frequencies(words):
# Implement the word_frequencies function.  The words function parameter is a string.
# Your solution here
     return {word: words.count(word) for word in words.split()}

```