-3

Write a function to concatenate a list of strings into a single string. For example: Input: (["this ", "is ", "a ", "string"]) == Output: "this is a string"

This is the code I have so far but it always returns with the ", " in the result which I have no idea how to get rid of it.

def concat(strings):

    list1 = []

    i = 0

    while i < len(strings):

        list1 += [strings[i]]
        i+=1

    return (list1)
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
pkim
  • 71
  • 2
  • 8

1 Answers1

-1

Python has a function for this - its called join. It is used on the delimiter you want, an you give the list of strings as the argument.

" ".join(strings)  # join strings with " " as delimiter

If you want just concatenation, you can use the empty string as delimiter - "".

Bendik
  • 1,097
  • 1
  • 8
  • 27