title: In Python, How can I get the next and previous key:value of a particular key in a dictionary?
body: <p>Okay, so this is a little hard to explain, but here goes:</p>
  
  <p>I have a dictionary, which I'm adding content to. The content is a hashed username (key) with an IP address (value). 
  I was putting the hashes into an order by running them against base 16, and then using Collection.orderedDict. 
  So, the dictionary looked a little like this:</p>
  
  <pre><code>d = {'1234': '8.8.8.8', '2345':'0.0.0.0', '3213':'4.4.4.4', '4523':'1.1.1.1', '7654':'1.3.3.7', '9999':'127.0.0.1'}
  </code></pre>
  
  <p>What I needed was a mechanism that would allow me to pick one of those keys, and get the key/value item one higher and one lower. So, for example, If I were to pick 2345, the code would return the key:value combinations '1234:8.8.8.8' and '3213:4.4.4.4'</p>
  
  <p>So, something like:</p>
  
  <pre><code>for i in d:
    while i &lt; len(d)
     if i == '2345':
       print i.nextItem
       print i.previousItem
       break()
  </code></pre>