changing numbers to spellings

MonkeeSage MonkeeSage at gmail.com
Sun Oct 1 01:05:33 EDT 2006


flyingisfun1217 at gmail.com wrote:
> Hey,
>
> Sorry to bother everybody again, but this group seems to have quite a
> few knowledgeable people perusing it.

Hi Tanner,

I've seen a few of those people; but let a dummy (me) try to help. ;)
As to the numbers to names question: do you need to know the names of
numbers higher than 9? I assume you do...but on the off chance you
don't, just make a list of names and get the index of the current
number in it. E.g.,

num2name = ['Zero', 'One', 'Two', 'Three', 'Four',
            'Five', 'Six', 'Seven', 'Eight', 'Nine']
numbers  = '1238573620'
names    = []
for n in numbers:
  names.append(num2name[int(n)])
print '-'.join(names)

If you need the actual names for like "Five Hundred and Sixty Seven", I
think one of the smart people 'round here will have to help with that.
I have some ideas, but I'm not very good at creating complex
algorithms.

Regards,
Jordan




More information about the Python-list mailing list