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. 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 an example parameter:
######################### def lastfirst(a): # list of last names lastNames=[] # list of first names firstNames=[] for x in a: n=x.find(',') # look for the comma lastNames.append(x[0:n]) # extract all symbols before ',' firstNames.append(x[n+2:]) # extract all symbols after ', ' return [firstNames, lastNames] # print the result
Comments
Leave a comment