Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to recover a list from string in python

# if you have list in string format and you want to convert it back into list type
# then you can use eval() function, for eg:
 
str_lst = "[code, in, python]"
lst = eval(str_lst)

output: [code, in, python]

# if you will try to use list() function, it won't help. 
# It will separate all element and make it all string
list(str_list)

output:
['[', 'c', 'o', 'd', 'e', ',', ' ', 'i', 'n', ',', ' ', 'p', 'y', 't', 'h', 'o', 'n', ']']
 
PREVIOUS NEXT
Tagged: #recover #list #string #python
ADD COMMENT
Topic
Name
6+7 =