title: All but the last N elements of iterator in Python
body: <p>What is the best way to get all but the last N elements of an iterator in Python?  Here is an example of it in theoretical action:</p>
  
  <pre><code>&gt;&gt;&gt; list(all_but_the_last_n(range(10), 0))
  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  &gt;&gt;&gt; list(all_but_the_last_n(range(10), 2))
  [0, 1, 2, 3, 4, 5, 6, 7]
  </code></pre>