Convert list to string using python

Firstly convert integers to string using strusing map function then use join function-

>>> ','.join(map(str,[10,"test",10.5]) )#since added comma inside the single quote output will be comma(,) separated
>>> '10,test,10.5'

Or if you want to convert each element of list into string then try-

>>> map(str,[10,"test",10.5])
>>> ['10', 'test', '10.5']

Or use itertools for memory efficiency(large data)

>>>from itertools import imap
>>>[i for i in imap(str,[10,"test",10.5])]
>>>['10', 'test', '10.5']

Or simply use list comprehension

>>>my_list=['10', 'test', 10.5]
>>>my_string_list=[str(i) for i in my_list]
>>>my_string_list
>>>['10', 'test', '10.5']

The easiest way is to send the whole thing to str() or repr():

>>> lists = [10, "test", 10.5]
>>> str(lists)
"[10, 'test', 10.5]"

repr() may produce a different result from str() depending on what's defined for each type of object in the list. The point of repr() is that you can send such strings back to eval() or ast.literal_eval() to get the original object back:

>>> import ast
>>> lists = [10, "test", 10.5]
>>> ast.literal_eval(repr(lists))
[10, 'test', 10.5]

a = ['b','c','d']
strng = ''
for i in a:
   strng +=str(i)
print strng

Tags:

Python

List