title: Python Dictionary min max
body: <p>I have a question regarding this code: The number of elements in the dict vary at every iteration:</p>
  
  <pre><code>d["one"] = 12
  d["two"] = 13
  d["three"] = 14
  
  maxkey, maxvalue = max(d.iteritems(), key=lambda x:x[1])
  minkey, minvalue = min(d.iteritems(), key=lambda x:x[1])
  </code></pre>
  
  <p>if the values for "one" "twor" etc. are different, everything is OK.</p>
  
  <p>Now assume the following:</p>
  
  <pre><code>d["one"] = 13
  d["two"] = 13
  
  
  maxkey, maxvalue = max(d.iteritems(), key=lambda x:x[1])
  minkey, minvalue = min(d.iteritems(), key=lambda x:x[1])
  </code></pre>
  
  <p>I want the following result: If the values are equal, then minkey, minvalue should be not the same as maxkey, maxvalue (it should be the other entry/or one of the others if there are several equal entries). Is there a simple way of implementing that in Python? Thank you very much for your help</p>
  
  <p>Example:</p>
  
  <pre><code>d["one"] = 12
  d["two"] = 12
  d["three"] = 12
  minkey, minvalue = min(d.iteritems(), key=lambda x:x[1])
  maxkey, maxvalue = max(d.iteritems(), key=lambda x:x[1])
  </code></pre>
  
  <p>Result</p>
  
  <pre><code>minkey = "three"
  maxkey = "three"
  </code></pre>
  
  <p>but I want, if </p>
  
  <pre><code>minkey = "three"
  </code></pre>
  
  <p>then maxkey should be</p>
  
  <pre><code>maxkey = "one"
  </code></pre>
  
  <p>or</p>
  
  <pre><code>maxkey = "two"
  </code></pre>