title: Create a dictionary out of a text file
body: <p>For example, lets say we have a .txt file named letters which contains,</p>
  
  <pre><code>a
  b
  b
  c
  d
  d
  d
  d
  </code></pre>
  
  <p>How would I go about creating a dictionary in which the keys are the individual letters found in the file and the values are the number of times each letter appears? For example, a would be a key and the corresponding value would be 1, while b is also a key and its value is 2.</p>
  
  <p>We just started learning opening files and creating dictionaries so I would assume I would start with something like,</p>
  
  <pre><code>file = open('letters.txt', 'rt') 
  </code></pre>
  
  <p>I am not quite sure if the rt part is right, but then we would have to search 'file' so,</p>
  
  <pre><code>for letter in file:
  </code></pre>
  
  <p>But I'm not quite sure how to search for letters, make them keys, and then add the number of times the letter occurs to the value in a dictionary. Any advice?</p>