title: python dictionary sorting oddly (want non-alphabetical)
body: <p>so I am trying to send a packet with some keys that i have put into a dictionary. these need to be printed in a specific order, so I've tried to make a function to reorder them. I assume python is doing something to rearrange in the order I don't want, but i'm not sure why.</p>
  
  <p>I'm currently using this function to try and achieve this.</p>
  
  <pre><code>def array_sort(array, sort): #yeah, it's array cuz i php like that.
      ordered = {}
      for i in range(0,len(sort)):
          if sort[i] in array:
              ordered[sort[i]] = array[sort[i]]
      keys = array.keys()
      return ordered 
  
  
  order = "l5,l4,l3,l2,q,y,k,k3,d1,z,p,c,b,d3,dt,N,n,a,h,v".split(',')
  keys = array_sort(infos, order)
  </code></pre>
  
  <p>for some reason this isn't working, <code>infos</code> is the list of keys in alphabetical order, i'm just not sure why the function is outputting the keys in an odd order. (a first, when 15 should be first :S)</p>
  
  <p>If you know a better way to do this feel free to tell me, I just recently started on python, so I'm not that familiar.</p>
  
  <p>EDIT:
  I was able to print the keys in the correct order using this immediately after making the order dictionary. even if it was just output as a string the order would be preserved (for the time being) and you could .split() it again to get the dictionary in the correct order (i think).</p>
  
  <pre><code>for i in range(0, len(order)):
      if order[i] in infos:
          packet += order[i] + '="' + infos[order[i]] + '" '
  </code></pre>