Computer Science, asked by vsounderam, 1 year ago

Write a phyton program to concatenate all elements in a list into string and return it

Answers

Answered by Anonymous
3

Answer:

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

Similar questions