Answers for "python parse string as list"

44

convert string to list python

# To split the string at every character use the list() function
word = 'abc'
L = list(word)
L
# Output:
# ['a', 'b', 'c']

# To split the string at a specific character use the split() function
word = 'a,b,c'
L = word.split(',')
L
# Output:
# ['a', 'b', 'c']
Posted by: Guest on February-18-2020
0

parse list from string

import ast

x = '["A","B","C","D"]'
x = ast.literal_eval(x)
x

# Returns: ['A', 'B', 'C', ' D']
Posted by: Guest on November-24-2021

Python Answers by Framework

Browse Popular Code Answers by Language