1

I am working on a python program in which i have to concatenate the characters in the list to make a string like ['h' 'e' 'l' 'l' 'o'] should be hello. I am using for loop to do this. I am searching for a built-in method that do this work. I searched but i didn't find any method. My code is:

list=['h','e','l','l','o']
    s=""
    for i in list:
        s+=i
    print(s)
  • 3
    Use `''.join(list)`. BTW, making a variable named same as built-in functions shadows the built-ins. Use something like `l` or `my_list`. – Chris Mar 12 '19 at 07:54

2 Answers2

0

Try join() method :

s = "".join(list)

OUTPUT :

s = 'hello'
Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56
0

Use join():

print ''.join(list)
Dorin
  • 1,016
  • 1
  • 11
  • 15