Is this recursive?

Viewed 60

Second attempt here, I just wanted to know if this is considered a recursive function.

The purpose of the function is to take a string and if the the first element is equal to the last element then append the last element to a list and return nothing, else call istelf and pass the same string from index [1] finally append the first element to the list

I know that error checking needs to be done on the if statement. However I am only doing this to try and get my head around recursion...Struggling to be honest.

Also I would never write a program like this if it where anything but trivial I just wanted to check if my understanding is correct so far.

def parse(theList):
    theList.reverse()
    parsedString = ''.join(theList)
    return parsedString




def recursiveMessage(theString):

    lastElement = theString[len(theString) - 1]

    if theString[0] == lastElement:
        buildString.append(theString[0])
        return None
    else:
        recursiveMessage(theString[1::])

    buildString.append(theString[0])





toPrint = "Hello Everyone!"
buildString = []   
recursiveMessage(toPrint)
print(parse(buildString))

Thanks again.

1 Answers
Related