unicode python 3.6的转换列表

2024-03-29 02:08:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个字符串列表,我想把这个列表字符串转换成unicode。我正在使用python3.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']

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

Tags: 字符串列表songunicodehelpcorpuscardstart
1条回答
网友
1楼 · 发布于 2024-03-29 02:08:40

我想你需要这样

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

注意:为python2版本提供了答案 根据Austin的评论,在python3中,文本字符串默认为unicode。因此不需要从外部转换。

相关问题 更多 >