From 085b59d339e89b851766382c3761597586f4f3f6 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Sat, 2 Oct 2010 00:58:36 -0500 Subject: Completely change implementation --- preprocess.py | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 preprocess.py (limited to 'preprocess.py') diff --git a/preprocess.py b/preprocess.py deleted file mode 100644 index 8474dc7..0000000 --- a/preprocess.py +++ /dev/null @@ -1,34 +0,0 @@ -import string -chars = string.lowercase - -def flub(word, wordlist): - for i in range(len(word)): - for c in chars: - new_word = word[:i] + c + word[i+1:] - if new_word != word and new_word in wordlist: - yield new_word - -def makegraph(wordlist): - g = {} - # bit of a hack to make an undirected graph - for w in wordlist: - for v in flub(w, wordlist): - g.setdefault(w, set()).add(v) - g.setdefault(v, set()).add(w) - return g - -def main(): - f = file('/usr/share/dict/words', 'rb') - bylength = {} - for line in f: - line = line.strip().lower() - bylength.setdefault(len(line), set()).add(line) - for length, wordlist in bylength.iteritems(): - print "processing", length - f = file('graph_%d.py' % length, 'wb') - f.write('# -*- encoding: latin-1 -*-\n') - f.write('graph = ' + repr(makegraph(wordlist)) + '\n') - f.close() - -if __name__ == '__main__': - main() -- cgit v1.2.3-70-g09d2