/phonewords

Primary LanguagePythonMIT LicenseMIT

phonewords

A simple Python library for converting to/from phonewords.

Usage

import phonewords

print(phonewords.digitize('HAT'))
# => '428'

print(phonewords.spell('428'))
# => {'4': ['G', 'H', 'I'], '2': ['A', 'B', 'C'], '8': ['T', 'U', 'V']}

print(phonewords.spell_all('428'))
# => ['GAT', 'GAU', 'GAV', 'GBT', 'GBU', 'GBV', 'GCT', 'GCU', 'GCV', 'HAT', 'HAU', 'HAV', 'HBT', 'HBU', 'HBV', 'HCT', 'HCU', 'HCV', 'IAT', 'IAU', 'IAV', 'IBT', 'IBU', 'IBV', 'ICT', 'ICU', 'ICV']

print(phonewords.spell_dict('2695'))
# => ['BOWL', 'COWL']

The library is also usable from the command line; python -m phonewords -h will provide help. Output is formatted on stdout in a human readable and/or machine-parseable manner.