-2

Would there be a way to convert '[0,0,0,0,0]' back into a list?

I've tried to convert it into an integer, which didn't work. I've searched online but the articles only talk about converting strings that are like 'A BIG HOUSE' into ['A','BIG','HOUSE'].

chrisprof
  • 7
  • 2

2 Answers2

-1

Yes, you can use ast.literal_eval

import ast
my_string = '[0,0,0,0,0]' 
my_list = ast.literal_eval(my_string)
Ron Serruya
  • 3,181
  • 1
  • 17
  • 24
-1
# without any import
s = '[0,0,0,0,0]'

# delete first and last character and split s with ',' delimiter
back_in_list = s[1:-1].split(",")

# list of str
print(back_in_list)

# list of int
list_of_int = [int(x) for x in back_in_list]
print(list_of_int)