python string list to list

38

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)

list to string python -

>>> L = [1,2,3]       
>>> " ".join(str(x) for x in L)
'1 2 3'

Comments

Submit
0 Comments