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

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to