Python Slice a List Using a List of Multiple Tuples
<p>I have a list of numbers that I would like to slice the range of numbers that is given from a list of multiple tuples. For example, I have a list that looks like:</p>

<pre><code>my_list = [ 5, 8, 3, 0, 0, 1, 3, 4, 8, 13, 0, 0, 0, 0, 21, 34, 25, 91, 61, 0, 0,] 
</code></pre>

<p>I also have a list of tuples that are the indicies of values that that I want that looks like:</p>

<pre><code>my_tups = [(5,9), (14,18)]
</code></pre>

<p>How would I return only the values of my_list using my_tups as an index?    </p>

<p>a possibility</p>

<pre><code>from itertools import chain

my_iter = chain(*[my_list[start:end] for start, end in my_tups])

[l for l in my_iter]
</code></pre>

<p>gives </p>

<pre><code>[1, 3, 4, 8, 21, 34, 25, 91]
</code></pre>

python list tuples slice