title: How do I sort dictionary by frequency and only printing the top 10 results?
body: <p>I'm making a function that gets the top dog names in NYC from a text file and prints the top 10.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>    for line in inputFile:
          fields = line.split("\t")
          nameList.append(fields[0])
  
      nameDict = {}
  
      for name in nameList:
          if name not in nameDict:
              nameDict[name] = 1
          else:
              nameDict[name] += 1
  
      keyList = []
  
      for name in nameDict:
          keyList.append(name)
  
      keyList.sort()
  
      for name in keyList:
          print(name, nameDict[name])
  </code></pre>
  
  <p>Here is an example of the text file:</p>
  
  <p>dog_name    gender  breed   birth   dominant_color  secondary_color third_color spayed_or_neutered  guard_or_trained    borough zip_code<br>
  Buddy   M   Afghan Hound    Jan-00  BRINDLE BLACK   n/a Yes No  Manhattan 10003<br>
  Nicole  F   Afghan Hound    Jul-00  BLACK   n/a n/a Yes No  Manhattan   10021</p>
  
  <p>Here is what happens now with my code:</p>
  
  <pre><code>"Keaton," 1
  "Lady,Princess,Prescott" 1
  "cathalina," 1
  A. 1
  A.A. 1
  ABBA 1
  ABBESS 1
  ABBEYROAD 1
  ABERCROMBIE 1
  ABIGALE 1
  </code></pre>