转换列表到unicode python 3.6

时间:2018-06-11 11:23:32

标签: python python-3.x

我有一个字符串列表,我想隐藏列表字符串到unicode。我正在使用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']

“但是neet语料库是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']

1 个答案:

答案 0 :(得分:3)

我认为你需要这样,

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

注意:为python 2版本提供的答案 根据Austin的评论,默认情况下,Literal字符串在Python 3中是unicode。因此您不需要在外部进行转换。