title: Using Dictionaries to Count First Letter in a String - Python
body: <p>I've been working on a dictionaries exercise in Python, and I'm fairly new to the language and programming in itself. I've been trying to take a string or list of strings and have my code compare the first letter of the strings and make a dictionary out of how many strings begin with a certain letter of the alphabet. This is what I have so far:</p>
  
  <pre><code>  d = {}
  text=["time","after","time"]
  # count occurances of character
  for w in text:
  
      d[w] = text.count(w)
  # print the result
  for k in sorted(d):
      print (k + ': ' + str(d[k]))
  </code></pre>
  
  <p>What I'm aiming for, is for example get the following result :</p>
  
  <pre><code>count_starts(["time","after","time"]) --&gt;{'t':  2,  'a':    1}
  </code></pre>
  
  <p>But, what I'm getting is more like the following:</p>
  
  <pre><code>count_starts(["time","after","time"]) --&gt; {time:2, after:1}
  </code></pre>
  
  <p>With what I have, I've been able to accomplish it counting how many times a whole unique string appears, just not the counting of JUST the first letter in the string.</p>
  
  <p>I also tried the following:</p>
  
  <pre><code>d = {}
  text=["time","after","time"]
  # count occurances of character
  for w in text:
      for l in w[:1]:
          d[l] = text.count(l)
  # print the result
  for k in sorted(d):
      print (k + ': ' + str(d[k]))
  </code></pre>
  
  <p>but all that give me in the printed output is :</p>
  
  <pre><code>{"a":0,"t":0}
  </code></pre>
  
  <p>I'm using Python Visualizer for my testing purposes.</p>