Python string list to list code example

Example 1: list to string python

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

Example 2: python convert list to list of strings

# 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

Example 3: string to list python

s = 'hello'
l = list(s)
print(l) # prints ['h', 'e', 'l', 'l', 'o']

Example 4: how to convert a string to a list python

#How to split a string into a list (Python)

#"separator" should be replaced with the string you want to split with
string.split("separator")

Example 5: python list of list to list of string

list_of_string = [''.join(element) for element in list_of_list]

Example 6: 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']