print the first item in list of lists
<p>I am trying to print the first item in a list of lists.  This is what I have:</p>

<p>My list is like this:</p>

<pre><code>['32 2 6 6', '31 31 31 6', '31 2 6 6']
</code></pre>

<p>My code is:</p>

<pre><code>from operator import itemgetter

contents = []
first_item = list(map(itemgetter(0), contents))
print first_item
</code></pre>

<p>but itemgetter only returns:
['3', '3', '3'] istead of ['32', '31', '31']
can I use a delimiter?</p>

<p>You are dealing with a list of strings, so you are getting the first index of each string, which is in fact <code>3</code> for all of them. What you should do is a comprehension where you split each string on space (which is the default of split) and get the first index:</p>

<pre><code>first_element = [s.split(None, 1)[0] for s in contents]
</code></pre>

<p>Inside the comprehension, the result of each <code>s.split(None, 1)</code> will actually be => </p>

<p><code>['32', '2 6 6']</code> <code>['31', '31 31 6']</code> <code>['31', '2 6 6']</code></p>

<p>and you get the first index of that. </p>

<p>Output:</p>

<pre><code>['32', '31', '31']
</code></pre>

python list