human
Complete the below
def appendTextElements(e, contentsList, se):

    ''''A helper function to convert text streams into the proper elements.'
    '''
assistant
#Here is the Python program you requested.
    def uconcat(text, newText, se):
        if (type(newText) != type(text)):
            if (type(text) is str):
                text = text.decode(se)
            else:
                newText = newText.decode(se)
        return (text + newText)
    e.text = ''
    lastElement = None
    for content in contentsList:
        if (not isinstance(content, Text)):
            newElement = content.toElement(se)
            if (newElement is None):
                continue
            lastElement = newElement
            lastElement.tail = ''
            e.append(lastElement)
        elif (lastElement is None):
            e.text = uconcat(e.text, content.text, se)
        else:
            lastElement.tail = uconcat(lastElement.tail, content.text, se)