#!/usr/bin/env python import sys, os, re, glob if __name__=='__main__': regdict = {0: "", 1: "", 2: "[abc]", 3: "[def]", 4: "[ghi]", 5: "[jkl]", 6: "[mno]", 7: "[pqrs]", 8: "[tuv]", 9: "[wxyz]" } words = [] for filename in glob.glob ("/usr/share/dict/*"): try: if not os.path.islink (filename): print "loading '%s'..." % filename words += file (filename).read ().split () except IOError: pass if len (words) == 0: print >> sys.stderr, "Keine Wortliste gefunden." sys.exit (1) if len (sys.argv) > 1: nr = sys.argv[1] else: nr = raw_input ("Telefonnummer: ") parts = re.findall ("[2-9]+", nr) for nr in parts: min_len = len (nr) while min_len == len (nr) or min_len > 1: i = 0 while len (nr[i: i+min_len]) == min_len: regex = "^%s$" % "".join ([regdict[int (c)] for c in nr[i: i+min_len]]) results = filter (re.compile (regex, re.I).findall, words) print nr[i: i+min_len] for w in results: print " ", w i += 1 min_len -= 1