title: Can I count on order being preserved in a Python tuple?
body: <p>I've got a list of datetimes from which I want to construct time segments.  In other words, turn <code>[t0, t1, ... tn]</code> into <code>[(t0,t1),(t1,t2),...,(tn-1, tn)]</code>.  I've done it this way:</p>
  
  <pre><code># start by sorting list of datetimes
  mdtimes.sort()
  # construct tuples which represent possible start and end dates
  
  # left edges
  dtg0 = [x for x in mdtimes]
  dtg0.pop()
  
  # right edges
  dtg1 = [x for x in mdtimes]
  dtg1.reverse()
  dtg1.pop()
  dtg1.sort()
  
  dtsegs = zip(dtg0,dtg1)
  </code></pre>
  
  <p>Questions...</p>
  
  <ol>
  <li>Can I count on tn-1 &lt; tn for any (tn-1,tn) after I've created them this way?  (Is ordering preserved?)</li>
  <li>Is it good practice to copy the original <code>mdtimes</code> list with list comprehensions?  If not how should it be done?</li>
  <li><p>The purpose for constructing these tuples is to iterate over them and segment a data set with <code>tn-1</code> and <code>tn</code>.  Is this a reasonable approach? i.e.</p>
  
  <pre><code>datasegment = [x for x in bigdata if ( (x['datetime'] &gt; tleft) and (x['datetime'] &lt; tright))] 
  </code></pre></li>
  </ol>
  
  <p>Thanks</p>