title: How to access the first and the last elements in a dictionary?
body: <p>Before posting, I have already gone through <a href="https://stackoverflow.com/questions/3097866/python-access-to-first-element-in-dictionary">Access an arbitrary element in a dictionary in Python</a>, but I'm uncertain about this.</p>
  <p>I have a long dictionary and I've to get the values of its first and last keys. I can use <code>dict[dict.keys()[0]]</code> and <code>dict[dict.keys()[-1]]</code> to get the first and last elements, but since the key:value pairs are outputted in a random form(as in the positioning of the key:value pairs is random), will the solution provided in this link always work?</p>