Q:

concatenate list of strings python

l = ['aaa', 'bbb', 'ccc']

s = ''.join(l)
print(s)
# aaabbbccc

s = ','.join(l)
print(s)
# aaa,bbb,ccc

s = '-'.join(l)
print(s)
# aaa-bbb-ccc

s = '\n'.join(l)
print(s)
# aaa
# bbb
# ccc
4
>>> sentence = ['this','is','a','sentence']
>>> '-'.join(sentence)
'this-is-a-sentence'
2
# Python program to demonstrate the 
# use of join function to join list 
# elements with a character. 
  
list1 = ['1','2','3','4']  
  
s = "-"
  
# joins elements of list1 by '-' 
# and stores in sting s 
s = s.join(list1) 
  
# join use to join a list of 
# strings to a separator s 
print(s) 

OUTPUT:
  1-2-3-4
8
listvalues = ['a', 'b', 'c']
concstring = ''.join(l)
0

New to Communities?

Join the community