I need cast a list to a string and get back the string to a list. There\'s a python way to make this behavior?
l1 = [\'aa\',\'bb\',\'cc\'] s = str(l1) l2 = c
You can use ast module:
import ast l1 = ['aa','bb','cc'] s = str(l1) ast.literal_eval(s) >>> ['aa','bb','cc']
Or something like this - but i don't like it too much:
l1 = ['aa','bb','cc'] s = str(l1) l2 = [x.strip(" '") for x in s.strip('[]').split(',')]