How to apply only the first names from a list with full names to a new list using a recursive function

Viewed 78

I have been trying to find a method to delete the last names and append the first names to a new list using this recursive function.

nameList = ['Julia Truong', 'Chen Wu', 'Jebb Castro', 'Ron Kenndey', 'X Y']

def convertName(nameList):
    if nameList == []:
        return [] 
 else:
    head = nameList[0:1]
    rest = nameList[1:]
    return head + convertName(rest)
 print(convertName(nameList))
2 Answers
Related