0

I know how to convert string to unicode using unicode("string", "utf-8") and I tried applying it to a dictionary. Well, my first solution is to loop everything (key and value) then convert them to unicode. But is there a fastest way to do this?

dict = {'firstname' : 'Foo', 'lastname' : 'Bar'} 

To

dict = {u'firstname' : u'Foo', u'lastname' : u'Bar'} 

Any help would be much appreciated. Thanks.

1
  • 1
    There's no shortcut - @perreal's answer is short and easy. Commented Nov 10, 2013 at 5:52

1 Answer 1

3

Just use the 'unicode' function:

d = {'firstname' : 'Foo', 'lastname' : 'Bar'} d = {unicode(k):unicode(v) for k,v in d.items() } 
Sign up to request clarification or add additional context in comments.

1 Comment

Wow! Never thought about this. Thanks!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.