Index the first and the last n elements of a list
<p>the first n and the last n element of the python list</p>

<pre><code>l=[1,2,3,4,5,6,7,8,9,10]
</code></pre>

<p>can be indexed by the expressions</p>

<pre><code>print l[:3]
[1, 2, 3]
</code></pre>

<p>and</p>

<pre><code>print l[-3:]
[8, 9, 10]
</code></pre>

<p>is there a way to combine both in a single expression, i.e index the first n and the last n elements using one indexing expression?</p>

<p>No, but you can use:</p>

<pre><code>l[:3] + l [-3:]
</code></pre>

python list