-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
  • 107,083
  • 22
  • 201
  • 376
pkim
  • 51
  • 2
  • 7

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
  • 975
  • 1
  • 7
  • 24