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>You can use the builtin <a href="https://docs.python.org/2/library/functions.html#slice" rel="nofollow">slice</a> as follows</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]
my_tups = [(5, 9), (14, 18)]

my_list2 = [my_list[slice(*o)] for o in my_tups]
print(my_list2)

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

python list tuples slice