Cosimo Curiale Cosimo Curiale - 14 days ago 7
Python Question

Python converting a list of strings to unicode

I have a list of strings that originally was a list of unicode element. And so, some string contains some character accent in unicode formate.

list=['Citt\xe0','Veszpr\xe9m','Publicit\xe0']


I need to get a new list that looks like this:

new_list=[u'Citt\xe0',u'Veszpr\xe9m',u'Publicit\xe0']


Each element of the new_list has to carry both the u and the accent.
Is there a way to do it iterating on each element?

Answer
new_list=[unicode(repr(word)) for word in old_list]

>>> print new_list 
[u"'Citt\\xe0'", u"'Hello'", u"'Publicit\\xe0'"]

Is that what you want?