String splitting within a list
<p>I'm supposed to create a function called <code>lastfirst()</code> that takes this input:
<code>['Gerber, Len', 'Fox, Kate', 'Dunn, Bob']</code></p>

<p>Then the function should return a list containing two lists of first names and last names, like this:
<code>[['Len', 'Kate', 'Bob'],['Gerber', 'Fox', 'Dunn']]</code></p>

<p>I'm not sure why this is causing me so many problems and I've tried so many different ways of figuring it out, but I just can't get it. Any help is appreciated. :)</p>

<p>Taking Jean-Francois's proposal one step further (BTW, he was right by not giving this answer)</p>

<ol>
<li>Flip name and surname in first step</li>
</ol>

<p><code>c = [[y.strip() for y in x.split(",")][::-1] for x in l]</code></p>

<p>The result is</p>

<pre><code>In [14]: c
Out[14]: [['Len', 'Gerber'], ['Kate', 'Fox'], ['Bob', 'Dunn']]
</code></pre>

<ol start="2">
<li>Re-arrange lists - asterick "unpacks" <em>c</em> as 3 consecutive lists of <em>[name, surname]</em> , and <em>zip</em> reshuffles 3 lists of length 2 into 2 lists of length 3</li>
</ol>

<p><code>result = zip(*c)</code></p>

<p>This is more advanced approach that you may find useful in the future</p>

python