title: Python - loop through list in specific order
body: <p>I have a list defined as:</p>
  
  <pre><code>pad = [unhexlify('00' * (16-j) + ('%02d' % j) * j) for j in range(1, 17)]
  </code></pre>
  
  <p>This constructs a pad list for a padding oracle attack. Due to how this attack works I need to cycle through elements 2-16, then if I don't get a hit go back and try the 1st element. Here is the loop:</p>
  
  <pre><code>for padsel in pad:  #increment pad
      print(str(hexlify(padsel)) +  "- selected pad")
      for i in range(256):    #increment guess
          g = unhexlify("000000000000000000000000000000" + "{:02x}".format(i)) 
          print(str(hexlify(g)) + "- guess")
          if attack(g,padsel,ct_prev, ct_target):
              m2 += "{:02x}".format(i)
              print(m2)
              break
          else:
              continue   
  m2 = m2[::-1] 
  print(m2 + "- m2")
  </code></pre>
  
  <p>How do I change the outer loop definition to do this?</p>
  
  <p>Pseudo code:</p>
  
  <pre><code>for padsel in pad (items 2-16):
      do stuff until hitting a break condition
  else:
      do stuff on element 1
  </code></pre>
  
  <p>Thanks.</p>