how is a dictionary sorted?
<p>Ladies and Gents,</p>

<p>I have a question about dictionaries in python.  While playing around I noticed something that <em>to me</em> seems strange.</p>

<p>I define a dict like this</p>

<p>stuff={'age':26,'name':'Freddie Mercury', 'ciy':'Vladivostok'}</p>

<p>I then add the word 'first' to stuff like this:</p>

<blockquote>
  <p>stuff[1]='first'</p>
</blockquote>

<p>When I print it out, it's fine</p>

<blockquote>
  <p>stuff</p>
  
  <p>{1: 'first', 'age': 26, 'name': 'Freddie Mercury', 'city': 'Vladivostok'}</p>
</blockquote>

<p>Then I add the word second:</p>

<blockquote>
  <p>stuff[2]='second'</p>
</blockquote>

<p>and that's fine, but when I display the content I get: </p>

<blockquote>
  <p>stuff</p>
  
  <p>{1: 'first', 'age': 26, 2: 'second', 'name': 'Freddie Mercury', 'city': 'Vladivostok'}</p>
</blockquote>

<p>** notice that 2 is now the third element, and not the second (in order) or the first (if elements are added to the beginning) element</p>

<p>And when I add in the third element 'wtf', now all of a sudden everything is back in order and I'm quite confused as to what's going on.  </p>

<blockquote>
  <p>stuff[3]='wtf'</p>
  
  <p>stuff</p>
  
  <p>{1: 'first', 2: 'second', 3: 'wtf', 'name': 'Freddie Mercury', 'age': 26, 'city': 'Vladivostok'}</p>
</blockquote>

<p>Could someone please explain to me what's going on here?</p>
