Abdul Razak
Abdul Razak

Reputation: 2794

How to convert list to unicode list

I have following list example

['Justice league', 'Avenger']

Now the problem i facing to convert list to unicode list
Unicode list example is

[u'Justice league', u'Avenger']

How can I achieve this? thank you for your response.

Upvotes: 4

Views: 9528

Answers (2)

Pynchia
Pynchia

Reputation: 11590

try applying unicode to its elements

>>> lst=['Justice league', 'Avenger']
>>> map(unicode,lst)
[u'Justice league', u'Avenger']

Obviously we are talking about Python 2 only, since literal strings are unicode by default in Python 3

Have a look at this Q&A on the same subject

Upvotes: 6

gtlambert
gtlambert

Reputation: 11961

Use the built in unicode function with a list comprehension:

x = ['Justice league', 'Avenger']
answer = [unicode(item) for item in x]

Upvotes: 2

Related Questions