technique to enter text using a mobile phone keypad (T9 dictionary-based disambiguation)

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Aug 9 16:45:41 EDT 2006


I've tested that sorting just the strings instead of the tuples (and
removing the stripping) reduces the running time enough:

    def __init__(self):
        numbers = '22233344455566677778889999'
        conv = string.maketrans(string.lowercase, numbers)
        lines =
file("/usr/share/dict/words").read().lower().splitlines()
        # lines = map(str.strip, lines)
        lines.sort()
        self.dict = [(word.translate(conv), word) for word in lines]

If the words file is already sorted you can skip the sorting line.
If the file contains extraneous spaces, you can strip them uncommenting
that line.

Bye




More information about the Python-list mailing list