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>Take advantage of <code>zip</code></p>

<pre><code>&gt;&gt;&gt; a = ['Gerber, Len', 'Fox, Kate', 'Dunn, Bob']
&gt;&gt;&gt; b = [i.split(', ') for i in a]
 list(zip(*b))
[('Gerber', 'Fox', 'Dunn'), ('Len', 'Kate', 'Bob')]
</code></pre>

<p>This returns a list of tuples, but if you truly want a list you can use <code>map</code></p>

<pre><code>&gt;&gt;&gt; list(map(list, (zip(*b))))
[['Gerber', 'Fox', 'Dunn'], ['Len', ' Kate', 'Bob']]
</code></pre>

<p>if you want to reverse the list just used the inbuilt <code>reversed</code> function</p>

python