#!/usr/bin/python
# -*- coding: utf-8 -*-

import sys

with open('/home/gdritter/downloads/censored-words.txt') as f:
    WORDS = set((s.strip().lower() for s in f.readlines()))

def find_variants(wd):
    if wd == 'of':
        return set(('on', 'if'))
    elif len(wd) == 1:
        return set((wd))
    res = set()
    for x in range(len(wd)):
        for c in [chr(y) for y in range(97, 123)]:
            new_word = wd[:x] + c + wd[x+1:]
            if wd[x] != c and new_word in WORDS:
                res.add(new_word)
    return res

def print_results(rs, ls, words):
    if ls == []:
        old = ' '.join(words).replace(' + ', '')
        new = ' '.join(rs[::-1]).replace(' + ', '')
        if old != new:
            print '{0} → {1}'.format(old, new)
    else:
        for x in ls[0]:
            print_results([x] + rs, ls[1:], words)

with open('/home/gdritter/spell-list.txt') as f:
    spell_list = [ln.split() for ln in f.readlines()]
for words in spell_list:
    for i in range(len(words)):
        rs = []
        for n, wd in enumerate(words):
            if n == i:
                rs.append(find_variants(wd))
            else:
                rs.append([wd])
        print_results([], rs, words)
