89 163
Assignments Done
98.1%
Successfully Done
In July 2020

# Answer to Question #6739 in Python for ALAN TING

Question #6739
Write a function lastfirst() that takes a list of strings as a parameter. Each string in the list has the format &#039;Last, First&#039; 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:

&gt;&gt;&gt; lastfirst([&#039;Gerber, Len&#039;, &#039;Fox, Kate&#039;, &#039;Dunn, Bob&#039;]
[[&#039;Len&#039;, &#039;Kate&#039;, &#039;Bob&#039;], [&#039;Gerber&#039;, &#039;Fox&#039;, &#039;Dunn&#039;]]
1
2012-02-23T09:32:52-0500
#########################
# code of the function

#########################
def lastfirst(a):
# list of last
names
lastNames=[]
# list of first names
firstNames=[]
for x in
a:
n=x.find(&#039;,&#039;) # look for the comma
lastNames.append(x[0:n]) # extract
all symbols before &#039;,&#039;
firstNames.append(x[n+2:]) # extract all symbols after
&#039;, &#039;
return [firstNames, lastNames] # print the
result

#########################
# test
command
#########################
print lastfirst([&#039;Gerber, Len&#039;, &#039;Fox,
Kate&#039;, &#039;Dunn, Bob&#039;])

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!