title: Why items order in a dictionary changed in Python?
body: <p>I am trying to learn Python from some tutorial. Here is a simple example I encountered that puzzles me.</p>
  
  <pre><code>&gt;&gt;&gt; d={"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
  
  &gt;&gt;&gt; d
  {'pwd': 'secret', 'database': 'master', 'uid': 'sa', 'server': 'mpilgrim'}
  
  &gt;&gt;&gt; d.keys()
  ['pwd', 'database', 'uid', 'server']
  
  &gt;&gt;&gt; d.values()
  ['secret', 'master', 'sa', 'mpilgrim']
  </code></pre>
  
  <p>As you can see in the first line where I define the dictionary, the item <code>"pwd":"secret"</code> is the last element in the dictionary. However, when I output the dictionary, it became the first element. And the rest part of the dictionary has been reordered.</p>
  
  <p>May I know why this is happening?</p>
  
  <p>If I use dict.keys() to extract the keys from a dictionary and iterate it in an order that I suppose it to be, will that cause mismatch problem?</p>