Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

FOR PYTHON: Write a function lastfirst() that takes a list of strings as a param

ID: 3759442 • Letter: F

Question

FOR PYTHON: Write a function lastfirst() that takes a list of strings as a parameter. Each string in the list has the format 'Last, First' where Last is a last name and First is a first name. You should assume that there are no spaces between the last name and the comma and that there are an arbitrary number of spaces between the comma and the first name. The function lastfirst() returns a list containing two sublists. The first sublist is a list of all the first names and the second sublist is a list of all the last names. The following shows how the function would be called on two example parameters:

Explanation / Answer

def lastfirst(names):
last_name = []
first_name = []
for name in names:
lfname = name.split(',')
last_name.append(lfname[0])
first_name.append(lfname[1].strip())

return last_name,first_name

last,first = lastfirst(['last, First','last1, First1'])
print last
print first