How to convert a random telephone number from a number into words from dictionaries and how to select it from a text and convert it in python?

前端 未结 1 425
陌清茗
陌清茗 2021-01-29 11:39

I am trying to convert a random telephone number from a number into words using dictionaries using the following code:

dict_1 = {07: \'zero seven\'}

dict_2 = {2         


        
相关标签:
1条回答
  • 2021-01-29 11:51

    Why not just:

    def phone(number):
        numbers = ['zero', 'one', 'two', 'three', 'four',
                   'five', 'six', 'seven', 'eight', 'nine']
        return ' '.join(numbers[c] for c in map(int, number))
    

    Result:

    >>> phone('0734123456')
    'zero seven three four one two three four five six'
    
    0 讨论(0)
提交回复
热议问题