String to dictionary word count and display
<p>I have a homework question which asks:</p>

<blockquote>
  <p>Write a function print_word_counts(filename) that takes the name of a
  file as a parameter and prints an alphabetically ordered list of all
  words in the document converted to lower case plus their occurrence
  counts (this is how many times each word appears in the file).</p>
</blockquote>

<p>I am able to get an out of order set of each word with it's occurrence; however when I sort it and make it so each word is on a new line the count disappears.</p>

<pre><code>    import re

def print_word_counts(filename):
    input_file = open(filename, 'r')
    source_string = input_file.read().lower()
    input_file.close()
    words = re.findall('[a-zA-Z]+', source_string)    

    counts = {}
    for word in words:
        counts[word] = counts.get(word, 0) + 1

    sorted_count = sorted(counts)
    print("\n".join(sorted_count))
</code></pre>

<p>When I run this code I get:</p>

<pre><code>a
aborigines
absence
absolutely
accept
after
</code></pre>

<p>and so on.</p>

<p>What I need is:</p>

<pre><code>a: 4
aborigines: 1
absence: 1
absolutely: 1
accept: 1
after: 1
</code></pre>

<p>I'm not sure how to sort it and keep the values.</p>