Convert String In List Format To List Python

[Solved] Convert String In List Format To List Python | Scheme - Code Explorer | yomemimo.com
Question : convert string in list format to list python

Answered by : arjun-mair

>>> 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']

Source : https://stackoverflow.com/questions/1894269/how-to-convert-string-representation-of-list-to-a-list | Last Update : Thu, 24 Mar 22

Question : convert list in string format to list python

Answered by : aman-kumar-verma

# if you have something like this, and you want to convert it
# actual python list
lst = '["Albert Einstein", "Isaac Newton"]'
# then you can use python `eval` function
lst = eval(lst)
# output
["Albert Einstein", "Isaac Newton"]

Source : | Last Update : Thu, 07 Sep 23

Answers related to convert string in list format to list python

Code Explorer Popular Question For Scheme