Apart from a digit, most telephones also depict a sequence of letters on each key of the device. Usually, the following mapping holds between letters and digits: 2=ABC, 3=DEF, 4=GHI, 5=JKL, 6=MNO, 7=PQRS, 8=TUV, 9=WXYZ. No letters are mapped to the keys 0 and 1. These letters have had several auxiliary uses.

The letters have also been used, mainly in the United States, as a way of remembering telephone numbers easily. For example, these letters were used as a reminder for telephone numbers (mainly in the United States). A company that sales flowers, could for example licence the phone number 1-800-356-9377 and advertise it as the mnemonic phone word 1-800-FLOWERS.

phone words

In recent times, the letters on the keys are needed also for entering text on mobile phones, for text messaging, entering names in the phone book, etc. A word is entered on a telephone supporting the T9 system (Text on 9 keys) by a single keypress for each key on which the letter is mapped. To enter the word Hello, one would press the following sequence of keys 4 (GHI), 3 (DEF), 5 (JKL), 5 (JKL) and 6 (MNO). The T9 system will then look up in a dictionary all words corresponding to the sequence of keypresses. If there are multiple words that correspond to the sequence of keypresses, the user can select the intended word from a list. This usually works a lot faster than each individual letter using multiple keypresses as in the MultiTap approach used in conventional mobile phone text entry.

Assignment

For this assignment you are asked to compose a dictionary that can be used by a mobile phone that supports the T9 system. This is done in the following way:

Example

>>> key('FLOWERS')
'3569377'
>>> key('surpassing')
'7877277464'
>>> key('brutifying')
'2788439464'
>>> key('hematurias')
'4362887427'

>>> dictionary(['languisher', 'requesters', 'desecrates', 'impostumes', 'recessions', 'fluoresces', 'franchisee', 'sequesters', 'holinesses', 'perverters', 'bellyacher', 'succincter', 'encourages', 'refinishes', 'lawbreaker', 'blabbering', 'effacement'])
{'5292732537': {'lawbreaker'}, '7378378377': {'sequesters', 'perverters', 'requesters'}, '5264847437': {'languisher'}, '3332236368': {'effacement'}, '4654637737': {'holinesses'}, '3726244733': {'franchisee'}, '7323774667': {'recessions'}, '4676788637': {'impostumes'}, '7334647437': {'refinishes'}, '3373272837': {'desecrates'}, '2355922437': {'bellyacher'}, '2522237464': {'blabbering'}, '7822462837': {'succincter'}, '3626872437': {'encourages'}, '3586737237': {'fluoresces'}}