代码之家  ›  专栏  ›  技术社区  ›  Carlos Salazar

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

  •  0
  • Carlos Salazar  · 技术社区  · 6 年前

    我需要生成一个数字序列,例如 1 to 100 (这个数字可能更大)在数组中,但像文本一样

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

    有这样的图书馆吗?还是我必须手动完成?如果有办法用西班牙语做,那就更好了。

    3 回复  |  直到 6 年前
        1
  •  0
  •   malmiteria    6 年前

    使用拐点:

    >>>import inflect
    >>>p = inflect.engine()
    >>>p.number_to_words(1234)
    u'one thousand, two hundred and thirty-four'
    
        2
  •  -1
  •   jaswanth    6 年前

    这可能会对你有所帮助,但要用西班牙语完成,你需要理解代码并稍微更改一下代码 https://www.geeksforgeeks.org/convert-number-to-words/

    编辑: 我认为这将对你更有帮助,因为这个模块支持多种语言 https://pypi.org/project/num2words/

        3
  •  -3
  •   Pat Larkin    6 年前

    你必须手动完成,只需使用replace。