I have the following:
a = """\"[""123456789"",""987654321""]\""""
I am trying to convert that to a list of strings. I’ve tried the following:
lst = ast.literal_eval(a)
but this returns all the characters as an individual string. What is the mistake I am doing?
The expected output: ["123456789", "987654321"]
>Solution :
You can try literal_eval twice to get a list of integers and then map each integer to strings like this :
from ast import literal_eval as le
lst = le(le(a))
lst = list(map(str, lst))
lst would now become ['123456789', '987654321']