xxxxxxxxxx
# Basic syntax using list comprehension:
lsit_of_strings = [str(i) for i in your_list]
# Example usage:
your_list = ['strings', 'and', 'numbers', 11, 23, 42]
lsit_of_strings = [str(i) for i in your_list]
print(lsit_of_strings)
--> ['strings', 'and', 'numbers', '11', '23', '42'] # List of strings
xxxxxxxxxx
>>> import ast
>>> x = '[ "A","B","C" , " D"]'
>>> x = ast.literal_eval(x)
>>> x
['A', 'B', 'C', ' D']
>>> x = [n.strip() for n in x]
>>> x
['A', 'B', 'C', 'D']
xxxxxxxxxx
# Python program to convert a list
# to string using list comprehension
s = ['I', 'want', 4, 'apples', 'and', 18, 'bananas']
# using list comprehension
listToStr = ' '.join([str(elem) for elem in s])
print(listToStr)
xxxxxxxxxx
my_list = ["Hello", 8, "World"]
string = " ".join(my_list)
print(string)
"""
output
Hello 8 World
"""
xxxxxxxxxx
list_of_num = [1, 2, 3, 4, 5]
# Covert list of integers to a string
full_str = ' '.join([str(elem) for elem in list_of_num])
print(full_str)
xxxxxxxxxx
ls = '[1,2,3]'
# use json module
import json
ls = json.loads(ls)
print(ls) # [1,2,3]
xxxxxxxxxx
>>> mylist = ['spam', 'ham', 'eggs']
>>> print ', '.join(mylist)
spam, ham, eggs
xxxxxxxxxx
lines2 = " ".join(lines) # Converts the list to a string.
# This should work for writing to a file
file.write(lines2)
xxxxxxxxxx
import ast
l1 = ['aa','bb','cc']
s = str(l1)
ast.literal_eval(s)
>>> ['aa','bb','cc']
xxxxxxxxxx
list_of_string = [''.join(element) for element in list_of_list]