l = "['Hello', 'my', 'name', 'is', 'Apple']"
l1 = ['Hello', 'my', 'name', 'is', 'Apple']
type(l)
returns str
but I want it to be a list, as l1
is.
How can I transform that string into a common list?
l = "['Hello', 'my', 'name', 'is', 'Apple']"
l1 = ['Hello', 'my', 'name', 'is', 'Apple']
type(l)
returns str
but I want it to be a list, as l1
is.
How can I transform that string into a common list?
the
ast
module has aliteral_eval
that does what you wantOutputs:
docs
ast.literal_eval is a nice approach. For those preferint string manipulation, another option is: