title: Replacing values in a dictionary when there is a higher value for a given key later in file?
body: <p>I'm a fairly new coder and having trouble with this problem - forgive me if any of my vocab is off.  I have a tab delimited text file with multiple columns, as below.  </p>
  
  <pre><code>Cat    2   32
  Dog    5   56
  Bird    10  234
  Dog  2   23
  Alligator    2   94
  Cat  10  34
  Tiger    2   973
  Bird    2   355
  </code></pre>
  
  <p>I want to use the first column as a key, and the second as a value.  If there is a repeat of a key, I want the dictionary to store the highest value in the text file.  For instance, I would want <code>Cat:10</code> and <code>Dog:5</code> as <code>key:value</code> pairs.</p>
  
  <p>I have opened the file and created a dictionary which takes the first column as the key and second as a value.  I have updated based on Shizzen83's super helpful advice to:</p>
  
  <pre class="lang-py prettyprint-override"><code>animals = '/path/animals.txt'
  file = open(animals, mode='r')
  
  top_scores = dict()
  for line in file :
      goodline = line.rstrip('\r\n')
      data = goodline.split("\t")
      top_scores[data[0]] = max(top_scores.setdefault(data[0], data[1]), data[1])
  
  print(top_scores)
  
  </code></pre>
  
  <p>The output then becomes:</p>
  
  <pre><code>{'Alligator': '2', 'Tiger': '2', 'Bird': '2', 'Dog': '5', 'Cat': '2'}
  </code></pre>
  
  <p>The desired output, however is:</p>
  
  <pre><code>{'Alligator': '2', 'Tiger': '2', 'Bird': '10', 'Dog': '5', 'Cat': '10'}
  </code></pre>
  
  <p>Any help to make it save the highest value in the file for a given key would be greatly appreciated!</p>