title: Sort dictionary by integers of dictionary keys
body: <p>Let's say I have a dictionary like so:</p>
  
  <pre><code>thedict={'1':'the','2':2,'3':'five','10':'orange'}
  </code></pre>
  
  <p>and I want to sort this dictionary by key. If I do the following:</p>
  
  <pre><code>for key,value in sorted(thedict.iteritems()):
       print key,value
  </code></pre>
  
  <p>I will obtain</p>
  
  <pre><code>1 the
  10 orange
  2 2
  3 five
  </code></pre>
  
  <p>since the keys are strings and not integers. I want to sort them as if they are integers, so the entry "10,orange" comes last. I thought something like this would work:</p>
  
  <pre><code>for key,value in sorted(thedict.iteritems(),key=int(operator.itemgetter(0))):
      print key,value
  </code></pre>
  
  <p>but that generated this error:</p>
  
  <pre><code>TypeError: int() argument must be a string or a number, not 'operator.itemgetter'
  </code></pre>
  
  <p>What am I doing wrong here? Thanks!</p>