Convert a List to a String

48

list to string python -

list1 = [1, 2, 3]
str1 = ''.join(str(e) for e in list1)

python string list to list -

>>> 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']

list to string python -

list1 = ['1', '2', '3']
str1 = ''.join(list1)

Convert a List to a String -

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
*/

Comments

Submit
0 Comments