Justin Azoff: > It takes a second or two to read the list of words in, Nice solution. If you want to speed up the initialization phase you may use something like this (it requires a bit more memory, because lines contains all the words).
Note that the words and numbers have the same sorting order, so you may use this to speed up the sorting a little, like doing it on words only (that is the lines list), but for small dictionaries sort is fast enough already, so this isn't much important. Note: you have to add another 9 to numbers, because z too is associated to 9. import string class Phone: def __init__(self): numbers = '22233344455566677778889999' convtable = string.maketrans(string.lowercase, numbers) lines = file("/usr/share/dict/words").read().lower().splitlines() words = [] for line in lines: word = line.strip() nums = word.translate(convtable) words.append( (nums, word) ) words.sort() self.dict = words p = Phone() Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list