I have the following list:
my_list = [ '[2,2]', '[0,3]' ]
I want to convert it into
my_list = [ [2,2], [0,3] ]
Is there any easy way to do this in Python?
>Solution :
One way to avoid eval is to parse them as JSON:
import json
my_list = [ '[2,2]', '[0,3]' ]
new_list = [json.loads(item) for item in my_list]
This would not only avoid the possible negative risks of eval on data that you don’t control but also give you errors for content that is not valid lists.