-2

[u'bangladesh', u'bhutan', u'maldives', u'nepal', u'sri lanka', u'united arab emirates', u'hong kong', u'malaysia', u'singapore', u'thailand', u'china', u'bahrain', u'iran (islamic republic of)', u'jordan', u'kuwait']

I dont want the u' in every item.

Anmol Gulati
  • 83
  • 2
  • 9

3 Answers3

2

No, you don't. Apart from anything else, that still wouldn't be valid JSON, because it has single quotes.

If you want JSON, you should ask for JSON.

return HttpResponse(json.dumps(a))
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
1

The u is just informational, meaning that the texts are unicode.

>>> country
[u'bangladesh', u'bhutan', u'maldives', u'nepal', u'sri lanka', u'united arab emirates', u'hong kong', u'malaysia', u'singapore', u'thailand', u'china', u'bahrain', u'iran (islamic republic of)', u'jordan', u'kuwait']
>>> for c in country:
...     print c
... 
bangladesh
bhutan
maldives
nepal
sri lanka
united arab emirates
hong kong
malaysia
singapore
thailand
china
bahrain
iran (islamic republic of)
jordan
kuwait
>>> import json
>>> json.dumps(country)
'["bangladesh", "bhutan", "maldives", "nepal", "sri lanka", "united arab emirates", "hong kong", "malaysia", "singapore", "thailand", "china", "bahrain", "iran (islamic republic of)", "jordan", "kuwait"]'
>>> 

So, you don't have to do anything, you just misunderstood what the u means

joel goldstick
  • 4,393
  • 6
  • 30
  • 46
-1

If you just want to remove u' from every item just replace the line

....
a.append(list_country[i])
...

by

....
a.append(str(list_country[i]))
....
florex
  • 943
  • 7
  • 9