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>This also works:</p>

<pre><code>people = ["Gerber, Len", "Fox, Kate", "Dunn, Bob", "Walsh, Jack"]

def lastfirst(the_list):
    name = []
    lastname = []
    for i in the_list:
        lastname.append(i.split(",")[0])
        name.append(i.split(", ")[1])
    firstlast = [name, lastname]    
    print (firstlast)
lastfirst(people)
</code></pre>

<p>Made a few corrections, this route is longer but maybe more beginner friendly, at least I would find it so. I realize the output depends on the input being given in correct form as was observed.</p>

python