如何从字典项中删除“u"(unicode) [英] How to remove 'u'(unicode) from a dictionary item

查看:117
本文介绍了如何从字典项中删除“u"(unicode)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将字典项转换为列表,但字典项包含要删除的u".例如:dictionary={u'test1': u'test1value', u'test2': u'test2value'}我用过

f = 字典output_list = f.items()返回输出列表

和 output_list 包含 (u'test1', u'test1value') ,(u'test2',u'test2value')

->但是,我期待 out_list 作为 ('test1', 'test1value') ,('test2','test2value) 这样我就可以将这些值与其他项目进行比较.请提供有关此问题的任何帮助.

解决方案

我不明白你的意思.您仍然可以将这些特定的 unicode 字符串与 ASCII 字符串进行比较:

<预><代码>>>>u_foo = u'foo'>>>富 = '富'>>>u_foo == foo真的

如果不能,请先尝试将字符串编码为不同的字符集.

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.

解决方案

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.

这篇关于如何从字典项中删除“u"(unicode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆