title: Python: Key error after using get()
body: <p>I have a code here which counts the number of similar second words in a line starting with 'From ', finds which one occurs the max number of times and prints the word along with its frequency. </p>
  
  <p>On the line using the get method, i get a Key Error:(insert second word here). This key error occurs for the first sentence itself and the loop doesn't iterate through. I have absolutely no clue why this is happening.</p>
  
  <pre><code>name = raw_input("Enter file:")
  fh = open(name)
  d=dict()
  max=0
  key=''
  for line in fh:
      line=line.rstrip()
      if line.startswith('From '):
          x=line.split()
          d[x[1]] = d.get(d[x[1]],0) + 1
  for z in d:
      if d[z]&gt;max:
          max=d[z]
          key = z
  print key, max
  </code></pre>
  
  <p>Thank You.</p>