Okay, so for some practice problems from a friend, he asked me to take some previous code, and define a function called parseName? I'm not familiar at all with what it is/does. The objective he gave me was to use this parseName function and to return the firstname, middlename, and lastname, in my code. How in the world do I implement this parse function to return what my code is already outputting?

My code is the following:

def getFirstName(fullname):
space = fullname.find(' ')
return fullname[0:space]

def getMiddleName(fullname):
count = fullname.count(' ')
old = fullname
new = ''
for i in range(count):
space = old.find(' ')
if i != 0:
new += old[:space] + ' '
old = old[space+1:]
return new

def getLastName(fullname):
count = fullname.count(' ')
temp = fullname
for i in range(count):
space = temp.find(' ')
temp = temp[space+1:]
return temp


name = 'Benjamin de la OMG I have a lot of middle names Franklin'

fname = getFirstName(name)
mname = getMiddleName(name)
lname = getLastName(name)


print(fname)
print(mname)


What is returned when code is run:

Benjamin
de la OMG I have a lot of middle names
Franklin

Recommended Answers

All 2 Replies

Key in "python first last middle name" in the Daniweb search box. You are one of many asking this question.

Key in "python first last middle name" in the Daniweb search box. You are one of many asking this question.

I am aware of that, but I am unsure of how to do this using 'parse' ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.