How to cut off a varying length tail from a list elegantly?
<p>I'm fairly new to Python, and this is a rather basic question.</p>

<p>I've got a list <code>lst</code> and have at some point computed an integer <code>n</code> with <code>0&lt;=n&lt;=len(lst)</code> that tells me that (for the purpose at hand) I should discard the final <code>n</code> elements of the list. The statement that comes to mind to achieve this is <code>del lst[-n:]</code> or maybe <code>lst[-n:]=[]</code> (I've found out that in either case adding <code>0</code> after the colon is not a good idea, as zero is not considered to be larger than <code>-n</code> in this setting). However both variants fail when <code>n==0</code>, as the list gets emptied entirely instead. Should I really insert an explicit test for zero here, or stoop down to writing</p>

<pre><code>del lst[len(lst)-n:]
</code></pre>

<p>or is there something more elegant (and reliable) that can be done here?</p>
