如何在python中生成一系列数字作为文本

2024-05-18 23:40:29 发布

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

我需要生成一个numbre序列,例如从数组中的1 to 100(这个数字可能要大得多)生成,但是像文本一样

[
    'one',
    'two',
    'three',
    ...
    'one hundred',
]

有这样的图书馆吗?或者我必须手动操作?如果有办法用西班牙语来做这件事,那就更好了


Tags: to文本图书馆序列数字数组手动one
3条回答

这可能会对您有所帮助,但为了用西班牙语完成这项工作,您需要理解代码并稍微修改代码 https://www.geeksforgeeks.org/convert-number-to-words/

编辑: 我认为这将有助于您在本模块中支持多种语言 https://pypi.org/project/num2words/

使用拐点:

>>>import inflect
>>>p = inflect.engine()
>>>p.number_to_words(1234)
u'one thousand, two hundred and thirty-four'

您必须手动执行此操作,只需使用“替换”

相关问题 更多 >

    热门问题