简体   繁体   中英

coversion list to unicode python 3.6

I have a list of strings and i want covert that list string into unicode. I am working in Python 3.6.

corpus
['love song',
 'cooki monster definit medal gold card mcdonald',
 'c start cup',
 'c',
 'h help bc cooki moster gott help',
 'cooki monster get diabet',
 'lll']

"but neet corpus to be unicode"

corpus
['love song',
 u'cooki monster definit medal gold card mcdonald',
 u'c start cup',
 'c',
 u'h help bc cooki moster gott help',
 u'cooki monster get diabet',
 'lll']

I think you need like this,

print [unicode(val,'utf-8') for val in l]

[u'love song', u'cooki monster definit medal gold card mcdonald', u'c start cup', u'c', u'h help bc cooki moster gott help', u'cooki monster get diabet', u'lll']

Note: Answer provided for python 2 version As per Austin commented, Literal strings are unicode by default in Python 3. So you don't need to convert externally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM