I have a string, something like:
a = "[1, 2, 3]"
If there an easy way to convert it in to a list, without using .split(), join() etc.
Thanks for any replies.
I have a string, something like:
a = "[1, 2, 3]"
If there an easy way to convert it in to a list, without using .split(), join() etc.
Thanks for any replies.
use ast.literal_eval()
it's safer than using eval
from ast import literal_eval
a = literal_eval("[1, 2, 3]")
print(a)