Slicing a range of elements in each sublist?
<p>I suspect there are more than one ways to do this in Python 2.7, but I'd like to be able to print the first three elements of each sublist in combos. Is there a way to do this without a loop? </p>

<pre><code>combos = [ [1,2,3,.14], [5,6,7,.18], [9,10,11,.12], [1,2,3,.15] ]
</code></pre>

<p>such that the output of a print statement would read:</p>

<pre><code>[ [1,2,3], [5,6,7], [9,10,11], [1,2,3] ]
</code></pre>

<p>***AFTER GETTING YOUR SUGGESTIONS:
I was struggling to see how this would work inside of my code structure but list comprehension can be done as part of an if statement like so, which I failed to recognize:</p>

<pre><code>p0combos = [ [1,2,3,.14], [5,6,7,.18], [9,10,11,.12], [1,2,3,.15] ]
p0 = [1, 2, 3]

if p0 not in [combo[:3] for combo in p0combos]:
    print combo[:3]
    print 'p0 not found'
else:
    print 'p0 found'
    print combo[3:4]
</code></pre>

<p>The output:</p>

<pre><code>p0 found
[0.15]
</code></pre>

<p>Thanks all.</p>

<blockquote>
  <p>I suspect there are more than one ways to do this in Python 2.7</p>
</blockquote>

<p>Yes and you can be quite creative with it. This is another alternative</p>

<pre><code>from operator import itemgetter

map(itemgetter(slice(3)), combos)
Out[192]: [[1, 2, 3], [5, 6, 7], [9, 10, 11], [1, 2, 3]]
</code></pre>

python list list-comprehension slice