Why am I getting a u letter for each element's name in a python set?
本问题已经有最佳答案,请猛点这里访问。
我正在使用TwitterAPI为python的twitter库做测试,我为一个特定的woid请求了所有的趋势主题,这个woid称为
然后我尝试在一个集合中获取每个特定的趋势名称,尝试以下方法:
1 2 | trendsSet = set(trend['name'] for trend in mexican_trends[0]['trends']) |
但
这是
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | [ { "created_at":"2014-01-17T18:51:20Z", "trends": [ { "url":"http://twitter.com/search?q=%23MentirasQueNoTienenPerdon", "query":"%23MentirasQueNoTienenPerdon", "name":"#MentirasQueNoTienenPerdon", "promoted_content": null, "events": null }, { "url":"http://twitter.com/search?q=%23FelizCumpleJLRoma", "query":"%23FelizCumpleJLRoma", "name":"#FelizCumpleJLRoma", "promoted_content": null, "events": null }, { "url":"http://twitter.com/search?q=%23EsDeChakas", "query":"%23EsDeChakas", "name":"#EsDeChakas", "promoted_content": null, "events": null }, { "url":"http://twitter.com/search?q=%22Jos%C3%A9+Sulaim%C3%A1n%22", "query":"%22Jos%C3%A9+Sulaim%C3%A1n%22", "name":"Jos\u00e9 Sulaim\u00e1n", "promoted_content": null, "events": null }, { "url":"http://twitter.com/search?q=%23RioRomaEnRitmoson", "query":"%23RioRomaEnRitmoson", "name":"#RioRomaEnRitmoson", "promoted_content": null, "events": null }, { "url":"http://twitter.com/search?q=%23TemasPerfectos", "query":"%23TemasPerfectos", "name":"#TemasPerfectos", "promoted_content": null, "events": null }, { "url":"http://twitter.com/search?q=%22Juan+Gelman%22", "query":"%22Juan+Gelman%22", "name":"Juan Gelman", "promoted_content": null, "events": null }, { "url":"http://twitter.com/search?q=Michoac%C3%A1n", "query":"Michoac%C3%A1n", "name":"Michoac\u00e1n", "promoted_content": null, "events": null }, { "url":"http://twitter.com/search?q=M%C3%A9xico", "query":"M%C3%A9xico", "name":"M\u00e9xico", "promoted_content": null, "events": null }, { "url":"http://twitter.com/search?q=TLCAN", "query":"TLCAN", "name":"TLCAN", "promoted_content": null, "events": null } ], "as_of":"2014-01-17T18:59:14Z", "locations": [ { "woeid": 23424900, "name":"Mexico" } ] } ] |
1 | set([u'#RioRomaEnRitmoson', u'M\xe9xico', u'#MentirasQueNoTienenPerdon', u'TLCAN', u'#EsDeChakas', u'#FelizCumpleJLRoma', u'Juan Gelman', u'#TemasPerfectos', u'Jos\xe9 Sulaim\xe1n', u'Michoac\xe1n']) |
如前所述,uith u字母作为每个元素的前缀,为什么?
《美国indicates that the preceding the character字符串字符串是Unicode字符串。Python文档at the http:/ / / / 2 docs.python.org howto unicode.html和其他问题在线交易usage of such as栈的Unicode编码()和()函数可以帮助你,如果你在Python中有特异性uses心灵,or need to,with them。P></
is that the means the U在Unicode字符串。P></