[Solved] Write a Python function to concatenate all elements (except the last element) of a given list into a string and return the string


def conexclast(strlst):
    '''
    function to concatenate all elements (except the last element) 
    of a given list into a string and return the string
    '''
    output = ""
    for elem in strlst:
       strng = str(elem)
       output = output+strng
    return ' '.join(strlst[0:-1])

print("Enter data: ")
strlst = raw_input().split()

print(conexclast(strlst))

The main correction is splitting the user’s input raw_input().split() and:

return ' '.join(strlst[0:-1])

that slices the string, just need to remove the parentheses

See more for str.split() and string slicing

0

solved Write a Python function to concatenate all elements (except the last element) of a given list into a string and return the string