codeObjC codeObjC - 1 month ago 14
Python Question

String Dict to Unicode coversion

I am new to python. I was wondering if there are any intuit functionality that I can use to go from string dict to unicode dict.

Input:

{'name': 'Lexus', 'model': 'GS F'}


Expected output:

{u'name': u'Lexus', u'model': u'GS F'}


Any comments / forwards to resources are welcomed.

Answer
>>> d={'name': 'Lexus', 'model': 'GS F'}
>>> d={k.decode('utf8'): v.decode('utf8') for k, v in d.items()}

output :

{u'model': u'GS F', u'name': u'Lexus'}
Comments