0

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'}
Cœur
39k25 gold badges207 silver badges282 bronze badges
asked Oct 20, 2016 at 22:49
4
  • Do you know how to go from str to unicode? Commented Oct 20, 2016 at 22:51
  • unicode(inputString, "utf-8") Commented Oct 20, 2016 at 22:56
  • 1
    If this is literally in source code, don't do it at runtime! Use from __future__ import unicode_literals. Commented Oct 20, 2016 at 22:58
  • If you are new to python, I suggest you start with Python3. Commented Oct 21, 2016 at 0:04

1 Answer 1

1
>>> 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'}
answered Oct 20, 2016 at 22:56
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.