title: Getting maximum value of each key in Python?
body: <p>I'm working on a problem in which I have one dictionary, but there exist duplicate keys within it. The goal is to get the maximum value of each corresponding key, but I am confused about how to do this because the previous examples I've seen show how to get the maximum value from the dictionary as a whole. Is there a way to compare one key with the rest of the keys, see if it is a match, and then examine their values? This is what I have tried so far:</p>
  <pre><code># Create mock dictionary with data
  gene_data = {'geneA': 1, 
      'geneB': 2, 
      'geneC': 0,
      'geneA': 3,
      'geneB': 1,
      'geneC': 4
  }
  
  # Pass in your dictionary as the parameter.
  # Return a newly created dictionary that displays each key once, alongside the maximum value.
  # For our example, our expected outcome is:
  # new_dict = {'geneA': 3, 'geneB': 2, 'geneC': 4}
  def get_max_value_from_data(data):
      new_dict = dict()
      for key, value in data.items():
          for i in range(0, len(data)):
              if key == data.keys()[i]:
                  if value &lt; data.values()[i]:
                      new_dict[key] = value
      return new_dict
      
  get_max_value_from_data(gene_data)
  </code></pre>