python convert list of object to list of string code example
Example 1: how to convert list into string in python
list_of_num = [1, 2, 3, 4, 5]
full_str = ' '.join([str(elem) for elem in list_of_num])
print(full_str)
Example 2: python convert list of lists to list of strings
['delim'.join([str(elem) for elem in sublist]) for sublist in my_list]
my_list = [[1, '1', 1], [2,'2',2], [3,'3',3]]
[' '.join([str(elem) for elem in sublist]) for sublist in my_list]
--> ['1 1 1', '2 2 2', '3 3 3']
my_list = [[1, '1', 1], [2,'2',2], [3,'3',3]]
['_'.join([str(elem) for elem in sublist]) for sublist in my_list]
--> ['1_1_1', '2_2_2', '3_3_3']
Example 3: list to string python
List = ["ITEM1", "ITEM2", "ITEM3"]
string_version = "".join(List)
print(string_version)
Example 4: python list of list to list of string
list_of_string = [''.join(element) for element in list_of_list]