title: How do I access the nth item in a dictionary or hash?
body: <p>I have a dictionary of keys and values, for example:</p>
  
  <pre><code>{
      fred: 1,
      dave: 2,
      lily: 3
  }
  </code></pre>
  
  <p>How do I get the 2nd element in the dictionary - <code>{dave:2}</code> in this case?</p>
  
  <hr>
  
  <p>Background: I've seen this question asked so many times on SO in one form or another, 
  so I thought I'd write a Q&amp;A page as a community wiki that folks can be
  referred to and which might hopefully become the canonical answer for this question.</p>
  
  <p>This Q&amp;A applies to dictionaries as they are implemented in many different
  languages. Different languages use different names to refer to what is
  essentially the same data structure - for example they're called hashes in
  Perl, dictionaries in Python. In Objective-C they're instances of the
  <code>NSDictionary</code> or <code>NSMutableDictionary</code> classes.</p>