I have a string, something like this: \"[[\'Cheese\', 72], [\'Milk\', 45], [\'Bread\', 22]]\".
\"[[\'Cheese\', 72], [\'Milk\', 45], [\'Bread\', 22]]\"
I want to convert this to a list. I know I can use eval(s
Try to use the json module:
import json s = "[['Cheese', 72], ['Milk', 45], ['Bread', 22]]" s = s.replace("'", '"') print json.loads(s)