Write function lastfirst that takes one argument a list of s
Write function lastfirst() that takes one argument- a list of strings of the format <LastName, FirstName> and returns a list consisting two lists:
(a) A list of all the first names
(b) A list of all the last names
>>> last([Gerber, Len\', \'Fox. Kate\', \"Dunn, Bob\'])
[[ \'Len\',\'Kate\', \'Bob\"], [\'Gerber\',\'Fox\',\'Dunn\"] ]
Python while loop
Solution
def lastfirst(l1):
first_names = []
last_names = []
for val in l1:
f, l = val.split(\',\')
first_names.append(f)
last_names.append(l.lstrip())
l2 = [first_names] + [last_names]
print(l2)
return l2
lastfirst([\'Gerber, Len\', \'Fox, Kate\', \'Dunn, Bob\'])
# I dont see there is a need to use while loop. If you still want to go with while loop please do inform me i will change it .
