Convert unicode list into python list -


this question has answer here:

s = u"['1', '2', '2', '1', '2']" print type(s) # <type 'unicode'> 

how can convert list here:

s = [1,2,2,1,2] 

you 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) in ast.literal_eval(s)] [1, 2, 2, 1, 2] 

Comments

Popular posts from this blog

How to run C# code using mono without Xamarin in Android? -

c# - SharpSsh Command Execution -

python - Specify path of savefig with pylab or matplotlib -