0

I'm doing tests for python's twitter library using Twitter API, I requested all trending topics for a specific WOEID, called this mexican_trends.

Then I tried to get every specific trend name in a set, tried this way:

trendsSet = set(trend['name']
            for trend in mexican_trends[0]['trends'])

But print dumps a u letter as prefix for every element in trendSet.

This is the print json.dumps(mexican_trends, indent=2)

[   {
    "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"
      }
    ]   
  } 
]

And trendsSet is printed as:

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'])

As said, uith u letters as prefix for each element, why?

diegoaguilar
  • 8,179
  • 14
  • 80
  • 129

2 Answers2

1

The u means that the string is in Unicode.

Alvaro Fuentes
  • 16,937
  • 4
  • 56
  • 68
1

The 'u' character preceding the string indicates that the string is a unicode string. The python docs at http://docs.python.org/2/howto/unicode.html and other questions on stack exchange such as Usage of unicode() and encode() functions in Python can help you if you have specific uses in mind, or need to operate with them.

Community
  • 1
  • 1
lagweezle
  • 516
  • 5
  • 12