list to string to list python code example
Example 1: convert list to string python
my_list = ["Hello", 8, "World"]
string = " ".join(my_list)
print(string)
"""
output
Hello 8 World
"""
Example 2: 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 3: convert string to list python
word = 'abc'
L = list(word)
L
word = 'a,b,c'
L = word.split(',')
L
Example 4: python3 create list from string
input = ['word1, 23, 12','word2, 10, 19','word3, 11, 15']
output = []
for item in input:
items = item.split(',')
output.append([items[0], int(items[1]), int(items[2])])