我有列表unicode的列表。现在我需要将它转换为列表字符串列表。我怎样才能做到这一点?将unicode列表转换为列表字符串
listoflist = [
[
u'keep', u'see', u'recover', u'try', u'cry', u'say', u'seem',
u'come', u'saw', u'have', u'be', u'begin', u'fell', u'wait',
u'come', u'wait', u'be', u'retire', u'be'
],
[
u'make', u'let', u'forget', u'forgive', u'punish', u'take', u'be',
u'take', u'forget', u'come', u'think', u'say', u'be', u'be', u'say',
u'think', u'jump', u'poke', u'come', u'be', u'have', u'try', u'come',
u'turn', u'approach', u'be', u'meet', u'try', u'run', u'boast',
u'bring', u'satisfy', u'use', u'be', u'leave', u'be', u'do', u'say',
u'bristle'
]
]
我试图用ast
库
import ast
d = []
for i in range(0,50):
d.append([item.encode('ascii') for item in ast.literal_eval(listoflist)])
,但我得到了下面的错误。
raise ValueError('malformed string')
ValueError: malformed string
不同的方法是受欢迎的。
?你应该**总是**提及带有Unicode问题的Python版本,因为在Python 3中处理Unicode的方式与在Python 2中处理Unicode的方式完全不同。 –
@ PM2Ring我明白了。是的,我正在使用Python版本2. – KevinOelen