xxxxxxxxxx
map(str, mylist)
#python 3+ map( ) doesn't output a list, which is why:
list(map(str, mylist)
#change 'str' to 'float' or 'int' for other outcomes
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
>>> 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
using System;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
List<string> list = new List<string>() { "A", "B", "C" };
char delim = ',';
string str = String.Join(delim, list);
Console.WriteLine(str);
}
}
/*
Output: A,B,C
*/