title: How to iterate more pythonic for a case?
body: <p>Here is the case:
  <code>mylist = range(100)</code> and I have a discontinuous path from <code>src=1</code> to <code>dest=99</code> with an array <code>pre[100]</code>, each value of which represents the last <code>elem</code> in the <code>path</code>.
  The question is: How can I get all the <code>elems</code> in the <code>path</code> from <code>dest</code> to <code>src</code>. Can do like this:</p>
  
  <pre><code>    path = []
      i = dst
      while i != src:
        path.append(i)
        i = pre[i]
      path.append(src)
  </code></pre>
  
  <p>But, is there any simpler way maybe using just only one statement?</p>
  
  <p><strong>Sample Input</strong></p>
  
  <pre><code>dst, src = 3, 2
  pre = [2, 0, 3, 1]
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>[3, 1, 0, 2]   #It just have to follow the path with the indices from 3 to 2.
  </code></pre>
  
  <p>Explanation:</p>
  
  <pre>
                src  dst
                  v  v
  Indices:  0  1  2  3
  Pre    :  2  0  3  1
  
  From dest 3, the predecessor is 1, so we go to 1.
  From node 1, the predecessor is 0, so we go to 0.
  From node 0, the predecessor is 2, so we go to 2.
  2 is src, so we're done.
  </pre>