s = u"['1', '2', '2', '1', '2']"
print type(s) # <type 'unicode'>
How can I convert this into list like here:
s = [1,2,2,1,2]
s = u"['1', '2', '2', '1', '2']"
print type(s) # <type 'unicode'>
How can I convert this into list like here:
s = [1,2,2,1,2]
You could use ast.literal_eval
function.
>>> import ast
>>> s = u"['1', '2', '2', '1', '2']"
>>> list(map(int, ast.literal_eval(s)))
[1, 2, 2, 1, 2]
OR
>>> [int(i) for i in ast.literal_eval(s)]
[1, 2, 2, 1, 2]