In a list of lists how to get all the items except the last one for each list?
<p>So I have this list of lists. Each nested list has <code>n+1</code> element where the first element are floats and the last one is an integer. I need to get , for each nested list, all the floats (so n elements out of <code>n+1</code>). Which is the best way to achieve that?</p>

<p>For example:</p>

<pre><code>x = [[0.1, 0.2, 1], [0.4, 0.05, 16], [0.3, 0.3, 5]]
output = [[0.1, 0.2], [0.4, 0.05], [0.3, 0.3]]
</code></pre>

<p>This is the shortest and easiest way:</p>

<pre><code>output = [l[:-1] for l in x]
</code></pre>

<p>It is called a <a href="https://docs.python.org/3.6/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension </a>.</p>

python list python-3.x