list - Can I count on order being preserved in a Python tuple? -


i've got list of datetimes want construct time segments. in other words, turn [t0, t1, ... tn] [(t0,t1),(t1,t2),...,(tn-1, tn)]. i've done way:

# start sorting list of datetimes mdtimes.sort() # construct tuples represent possible start , end dates  # left edges dtg0 = [x x in mdtimes] dtg0.pop()  # right edges dtg1 = [x x in mdtimes] dtg1.reverse() dtg1.pop() dtg1.sort()  dtsegs = zip(dtg0,dtg1) 

questions...

  1. can count on tn-1 < tn (tn-1,tn) after i've created them way? (is ordering preserved?)
  2. is practice copy original mdtimes list list comprehensions? if not how should done?
  3. the purpose constructing these tuples iterate on them , segment data set tn-1 , tn. reasonable approach? i.e.

    datasegment = [x x in bigdata if ( (x['datetime'] > tleft) , (x['datetime'] < tright))]  

thanks

  1. tuple order insert values tuple. they're not going sorted think you're asking. zip again, retain order inserted values in.

  2. it's acceptable method, have 2 alternate suggestions: use copy module, or use dtg1 = mdtimes[:].

  3. sounds reasonable.


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -