python convert string list to list code example
Example 1: convert list to string python
s = ['I', 'want', 4, 'apples', 'and', 18, 'bananas']
listToStr = ' '.join([str(elem) for elem in s])
print(listToStr)
Example 2: convert list to string python
my_list = ["Hello", 8, "World"]
string = " ".join(my_list)
print(string)
"""
output
Hello 8 World
"""
Example 3: string list into list pandas
import ast
ini_list = "[1, 2, 3, 4, 5]"
res = ast.literal_eval(ini_list)
print ("final list", res)
print (type(res))
Example 4: python convert string to list
fruit = 'apple oranges banans'
newlist = fruit.split()
print(newlist)
Example 5: string to list python
s = 'hello'
l = list(s)
print(l)
Example 6: convert string to list python
word = "Hey Hello world"
print(list(word))