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

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -