Search code examples
pythonstringunicodeoperation

Unicode - String - list Manipulation


I have a data s = u"[u'38', u'36', u'34', u'32']" which has data type unicode i want to make this data as simple list of element like s= ['38','36','32'],
i try to use simplejson.loads but its not working simple json work with the ('["s"]') this type of string not ("['s']") so any buddy please guide me to get of this problem

thanks in advance


Solution

  • >>> import ast
    >>> s = u"[u'38', u'36', u'34', u'32']"
    >>> [ item.encode('ascii') for item in ast.literal_eval(s) ]
    ['38', '36', '34', '32']