PKR
PKR

Reputation: 187

How to remove 'u'(unicode) from a dictionary item

I am trying to convert dictionary item into a list ,But the dictionary item contains 'u' which is to be removed. Ex: dictionary={u'test1': u'test1value', u'test2': u'test2value'} I have used

f = dictionary
output_list = f.items()
return output_list

and output_list contains (u'test1', u'test1value') ,(u'test2',u'test2value')

->But, I am expecting out_list as ('test1', 'test1value') ,('test2','test2value) So that I can compare these values with other item. Please provide any help on this issue.

Upvotes: 0

Views: 818

Answers (1)

rleppink
rleppink

Reputation: 25

I am not sure what you mean. You can still compare these specific unicode strings to ASCII strings:

>>> u_foo = u'foo'
>>> foo = 'foo'
>>> u_foo == foo
True

If somehow you can't, try encoding the string into a different charset first.

Upvotes: 2

Related Questions