我有一个从中想要将数字转换为文本等价物的字符串列表。例如。 2两个将数字转换为单词
这是结果样子:
[
['nn', 'known', 'tsutsumi', 'father', 'yasujiro', 'sow', 'seed', 'family', 'dominion'],
['un', 'secretari', 'gener', 'kofi', 'annan', 'appoint', 'special', 'repres', 'iraq', 'help', 'improv', 'commun', 'iraqi', 'leader'],
['year', '2016']
]
这里是我的代码:
from num2words import num2words
result=[]
with open("./Stemmingg.txt") as filer:
for line in filer:
result.append(line.strip().split())
temp=[]
for item in result:
r=num2words(item)
temp.append(r)
然而,这给了我该说的错误:
TypeError: type(['nn', 'known', 'tsutsumi', 'father', 'yasujiro', 'sow', 'seed', 'family', 'dominion']) not in [long, int, float]
我没有看到在'result'您提供... – Will
任何符号,并且你的输入总是一个列表列表,或者列表项只是一个简单的字符串? – Will
@ will:在整个*结果*中有一些数字,我只是举一些例子来显示* result *的样子。输入始终是列表的列表。 – minks