0

Lets say I have a list:

a = ['a','b','c']

which is list of string.

Now I want to iterate in such way that I get abc . How can I do that ?

varad
  • 7,309
  • 20
  • 60
  • 112

3 Answers3

4
"".join(a)

should do it for you.

or

 "".join(map(str, a))

if all elements are not strings

vks
  • 67,027
  • 10
  • 91
  • 124
0

Another slightly less pythonic way:

string = ''
for letter in a:
    string += letter
Maikflow
  • 191
  • 1
  • 8
0

Another alternative to one mentioned by vks. This assumes that the list contains elements which are str or support the + operator in a way that it aligns with the semantics of appending.

functools.reduce(lambda x,y: x+y, ['a','b','c'])
bashrc
  • 4,725
  • 1
  • 22
  • 49