I have a string representing a nested list:
string = [[1,2,3],[4,5,6]]
And a would like to convert it to a list:
list = [[1, 2, 3], [4, 5, 6]]
I’ve tried using string.split("]'[").split(', ') but it still returning [ ['1,2,3],[4,5,6'] ]
Any help? Thanks!
>Solution :
Assuming that you have a string like string = "[[1,2,3],[4,5,6]]" and you want to convert it to a list object like lst = [[1,2,3],[4,5,6]], you could simply use the eval method:
lst = eval(string)