title: how to remove an entry from orderedDict in python
body: <p>I am trying to obtain top 20 entries from a dictionary based on value. I used orderedDict to sort the entries by value. But when i'm trying to delete an entry from the orderedDict(to maintain a constant length of orderedDict i.e. 20) it doesnt happen.</p>
  
  <p>I wrote the following code:</p>
  
  <pre><code>while linecount&gt;0:
      line=images.readline().split()
      #compute "score" for each line
      if (len(result)&lt;20):
          result.update({(str(line)):score})
      else:
              if(len(result)==20):
                     result=OrderedDict(sorted(result.items(), key=lambda t: t[1]))
                     if(result.items()[0][1]&lt;score):
                         del result.items()[0]
                         temp=str(line)
                         result.update({temp:score})
  </code></pre>
  
  <p>But the delete/remove does not happen at the step:</p>
  
  <pre><code> del result.items()[0]
  </code></pre>
  
  <p>and the length of result remains 21 once it gets to that(21) value</p>
  
  <p>what am i doing wrong, how else could i do it?</p>