2024-heraklion-data/exercises/anagrams/anagrams_solution.ipynb
2024-08-27 15:27:53 +03:00

60 KiB

Exercise: Find the anagrams for all words in a list

  • You are given an English dictionary containing M words (“the dictionary”), and a separate list of N words (“the input”, saved in the file words_to_search.txt)
  • For each word in the input, find all the anagrams in the dictionary (e.g., for input 'acme' the anagrams are ['acme', 'came', 'mace'])

How to proceed?

  1. Write an algorithm to find all anagrams for one input word first
  2. What is the Big-O class of this algorithm when executed the full N-words input?
  3. Is there a way to pre-process the dictionary to improve the Big-O performance?

1. Load the system dictionary and the input words

In [7]:
# Load the system dictionary
with open('/usr/share/dict/words', 'r') as f:
    dict_words = [w.strip() for w in f.readlines()]
In [8]:
# Print the start and end of the dictionary
dict_words[:5] + ['...'] + dict_words[-5:]
Out[8]:
['A',
 'a',
 'aa',
 'aal',
 'aalii',
 '...',
 'zythem',
 'Zythia',
 'zythum',
 'Zyzomys',
 'Zyzzogeton']
In [13]:
# Load the input words
with open('words_to_search.txt', 'r') as f:
    words = [w.strip() for w in f.readlines()]
In [14]:
# Print the start and end of the input list
words[:5] + ['...'] + words[-5:]
Out[14]:
['acer',
 'acers',
 'aces',
 'aches',
 'acme',
 '...',
 'yap',
 'yaw',
 'yea',
 'zendo',
 'zoned']

2. Look for the anagrams of one input word, e.g. "organ"

  • There are several anagrams, including "groan" and "argon".

  • What is the Big-O performance oh your algorithm? In terms of M, the number of words in the dictionary, and K, the number of letters in a word

In [15]:
word = 'organ'
In [16]:
anagrams = []
for dict_word in dict_words:  # O(M)
    if sorted(word) == sorted(dict_word):  # 2 * O(K log K) ~ O(K log K)
        anagrams.append(dict_word)  # O(1)
In [17]:
anagrams
Out[17]:
['angor',
 'argon',
 'goran',
 'grano',
 'groan',
 'nagor',
 'orang',
 'organ',
 'rogan']

The performance of this implementation is O(M * K log K).

Note that instead of sorting , we could use a dictionary mapping letters to letter counts. This would make the performance even better, O(M * K)! However, in practice it would make little difference and would make the code more complicated, so we'll leave it like this.

3. Look for the anagrams of the words in the input list

  • How does the Big-O performance of your one-word implementation scale to an input list of M words?
  • Is there a way to pre-process the dictionary words in a data structure that is better suited for this task?
In [18]:
# Naive implementation, it takes a long time

def find_anagrams(word, dict_words):
    anagrams = []
    for dict_word in dict_words:   # O(N)
        if sorted(word) == sorted(dict_word):  # O(K log K)
            anagrams.append(dict_word)  # O(1)
    return anagrams

words_anagrams = []
for word in words:  # O(M)
    anagrams = find_anagrams(word, dict_words)
    words_anagrams.append((word, anagrams))  # O(1)
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
Cell In[18], line 12
     10 words_anagrams = []
     11 for word in words:  # O(M)
---> 12     anagrams = find_anagrams(word, dict_words)
     13     words_anagrams.append((word, anagrams))

Cell In[18], line 6, in find_anagrams(word, dict_words)
      4 anagrams = []
      5 for dict_word in dict_words:   # O(N)
----> 6     if sorted(word) == sorted(dict_word):  # O(K log K)
      7         anagrams.append(dict_word)  # O(1)
      8 return anagrams

KeyboardInterrupt: 

The complexity of this algorithm is O(M N KlogK), where M is the length of the list of words to search, N is the length of words in the dictionary, and K is the length of words.

What if we pre-process the dictionary in a data structure that is better suited for this task?

In [19]:
anagrams_map = {}
for dict_word in dict_words:  # O(N)
    letters = tuple(sorted(dict_word))  # O(K log K)
    if letters not in anagrams_map:  # O(1)
        anagrams_map[letters] = []  # O(1)
    anagrams_map[letters].append(dict_word)  # O(1)
In [20]:
words_anagrams = []
final_words = []
for word in words:  # O(M)
    letters = tuple(sorted(word))  # O(K log K)
    if letters not in anagrams_map:  # O(1)
        print('This word is not in the system dictionary -- skipping', word)
        continue
    else:
        final_words.append(word)
    words_anagrams.append((word, anagrams_map[letters]))  # O(1)
In [21]:
words_anagrams
Out[21]:
[('acer', ['acre', 'care', 'crea', 'race']),
 ('acers', ['carse', 'caser', 'ceras', 'scare', 'scrae']),
 ('aces', ['case', 'esca']),
 ('aches', ['chase']),
 ('acme', ['acme', 'came', 'mace']),
 ('acned', ['dance', 'decan']),
 ('acre', ['acre', 'care', 'crea', 'race']),
 ('acres', ['carse', 'caser', 'ceras', 'scare', 'scrae']),
 ('act', ['act', 'cat']),
 ('acts', ['cast', 'scat']),
 ('acyl', ['acyl', 'clay', 'lacy']),
 ('add', ['add', 'dad']),
 ('adverb', ['adverb']),
 ('aesc', ['case', 'esca']),
 ('aether', ['heater', 'hereat', 'reheat']),
 ('aethers', ['thereas']),
 ('afield', ['afield', 'defial']),
 ('aft', ['aft', 'fat']),
 ('agree', ['agree', 'eager', 'eagre']),
 ('agrees', ['grease']),
 ('ags', ['gas', 'sag']),
 ('ah', ['ah', 'ha']),
 ('ahs', ['ash', 'sah', 'sha']),
 ('aide', ['aide', 'idea']),
 ('aides', ['aside']),
 ('airings', ['raising']),
 ('airmen', ['marine', 'remain']),
 ('alloy', ['alloy', 'loyal']),
 ('almes', ['amsel', 'mesal', 'samel']),
 ('alp', ['alp', 'lap', 'pal']),
 ('alps', ['salp', 'slap']),
 ('altern', ['altern', 'antler', 'learnt', 'rental', 'ternal']),
 ('altrices', ['altrices', 'selictar']),
 ('alts', ['last', 'salt', 'slat']),
 ('am', ['am', 'ma']),
 ('amen', ['amen', 'enam', 'mane', 'mean', 'name', 'nema']),
 ('amp', ['amp', 'map', 'pam']),
 ('amps', ['samp', 'spam']),
 ('anglist', ['lasting', 'salting', 'slating', 'staling']),
 ('anils', ['sinal', 'slain', 'snail']),
 ('ant', ['ant', 'nat', 'tan']),
 ('antis', ['saint', 'satin', 'stain']),
 ('antler', ['altern', 'antler', 'learnt', 'rental', 'ternal']),
 ('antlers', ['saltern', 'starnel', 'sternal']),
 ('any', ['any', 'nay', 'yan']),
 ('ape', ['ape', 'pea']),
 ('aper', ['aper', 'pare', 'pear', 'rape', 'reap']),
 ('apt', ['apt', 'pat', 'tap']),
 ('arb', ['bar', 'bra', 'rab']),
 ('arc', ['arc', 'car']),
 ('arcs', ['scar']),
 ('are', ['aer', 'are', 'ear', 'era', 'rea']),
 ('ared', ['ared', 'daer', 'dare', 'dear', 'read']),
 ('ares', ['arse', 'rase', 'sare', 'sear', 'sera']),
 ('argle', ['argel', 'ergal', 'garle', 'glare', 'lager', 'large', 'regal']),
 ('aril', ['aril', 'lair', 'lari', 'liar', 'lira', 'rail', 'rial']),
 ('arising', ['raising']),
 ('arm', ['arm', 'mar', 'ram']),
 ('armpit', ['armpit', 'impart']),
 ('arms', ['arms']),
 ('arse', ['arse', 'rase', 'sare', 'sear', 'sera']),
 ('art', ['art', 'rat', 'tar', 'tra']),
 ('article', ['article', 'recital']),
 ('articles', ['altrices', 'selictar']),
 ('arts', ['sart', 'star', 'stra', 'tars', 'tsar']),
 ('arty', ['arty', 'atry', 'tray']),
 ('ash', ['ash', 'sah', 'sha']),
 ('aside', ['aside']),
 ('aspired', ['despair', 'pardesi']),
 ('asps', ['pass']),
 ('ate', ['ate', 'eat', 'eta', 'tae', 'tea']),
 ('ates', ['ates', 'east', 'eats', 'sate', 'seat', 'seta']),
 ('atoners', ['noreast', 'rosetan', 'seatron', 'senator', 'treason']),
 ('attic', ['attic', 'tacit']),
 ('aves', ['save', 'vase']),
 ('aye', ['aye', 'yea']),
 ('backward', ['backward', 'drawback']),
 ('bad', ['bad', 'dab']),
 ('bag', ['bag', 'gab']),
 ('bake', ['bake', 'beak']),
 ('baker', ['baker', 'brake', 'break']),
 ('balm', ['balm', 'lamb']),
 ('bar', ['bar', 'bra', 'rab']),
 ('bare', ['bare', 'bear', 'brae']),
 ('bast', ['bast', 'bats', 'stab']),
 ('bat', ['bat', 'tab']),
 ('batlet', ['battel', 'battle', 'tablet']),
 ('bats', ['bast', 'bats', 'stab']),
 ('battel', ['battel', 'battle', 'tablet']),
 ('battle', ['battel', 'battle', 'tablet']),
 ('beak', ['bake', 'beak']),
 ('bear', ['bare', 'bear', 'brae']),
 ('begin', ['begin', 'being', 'binge']),
 ('being', ['begin', 'being', 'binge']),
 ('below', ['below', 'bowel', 'elbow']),
 ('best', ['best']),
 ('bets', ['best']),
 ('binge', ['begin', 'being', 'binge']),
 ('blam', ['balm', 'lamb']),
 ('blot', ['blot', 'bolt']),
 ('blow', ['blow', 'bowl']),
 ('bludier', ['builder', 'rebuild']),
 ('bluest', ['bustle', 'sublet', 'subtle']),
 ('bluets', ['bustle', 'sublet', 'subtle']),
 ('bolt', ['blot', 'bolt']),
 ('bombed', ['bombed']),
 ('borde', ['boder', 'orbed']),
 ('bored', ['boder', 'orbed']),
 ('bores', ['boser', 'brose', 'sober']),
 ('boss', ['boss']),
 ('bourne', ['unrobe']),
 ('bowel', ['below', 'bowel', 'elbow']),
 ('bowl', ['blow', 'bowl']),
 ('bra', ['bar', 'bra', 'rab']),
 ('brae', ['bare', 'bear', 'brae']),
 ('brag', ['brag', 'garb', 'grab']),
 ('brake', ['baker', 'brake', 'break']),
 ('braved', ['adverb']),
 ('break', ['baker', 'brake', 'break']),
 ('brief', ['bifer', 'brief', 'fiber']),
 ('brose', ['boser', 'brose', 'sober']),
 ('brush', ['brush', 'shrub']),
 ('buhrs', ['brush', 'shrub']),
 ('builder', ['builder', 'rebuild']),
 ('burden', ['bunder', 'burden', 'burned', 'unbred']),
 ('burned', ['bunder', 'burden', 'burned', 'unbred']),
 ('bury', ['bury', 'ruby']),
 ('bush', ['bush']),
 ('bust', ['bust', 'stub']),
 ('bustle', ['bustle', 'sublet', 'subtle']),
 ('but', ['but', 'tub']),
 ('butles', ['bustle', 'sublet', 'subtle']),
 ('buts', ['bust', 'stub']),
 ('cab', ['bac', 'cab']),
 ('cabs', ['scab']),
 ('cadres', ['sacred']),
 ('cafe', ['face']),
 ('caller', ['caller', 'cellar', 'recall']),
 ('calm', ['calm', 'clam']),
 ('calo', ['alco', 'coal', 'cola', 'loca']),
 ('came', ['acme', 'came', 'mace']),
 ('caned', ['dance', 'decan']),
 ('canoe', ['acone', 'canoe', 'ocean']),
 ('cans', ['scan']),
 ('cape', ['cape', 'cepa', 'pace']),
 ('car', ['arc', 'car']),
 ('care', ['acre', 'care', 'crea', 'race']),
 ('cares', ['carse', 'caser', 'ceras', 'scare', 'scrae']),
 ('caret',
  ['caret',
   'carte',
   'cater',
   'crate',
   'creat',
   'creta',
   'react',
   'recta',
   'trace']),
 ('carol', ['calor', 'carol', 'claro', 'coral']),
 ('carp', ['carp', 'crap']),
 ('cars', ['scar']),
 ('carse', ['carse', 'caser', 'ceras', 'scare', 'scrae']),
 ('carte',
  ['caret',
   'carte',
   'cater',
   'crate',
   'creat',
   'creta',
   'react',
   'recta',
   'trace']),
 ('case', ['case', 'esca']),
 ('cask', ['cask', 'sack']),
 ('cast', ['cast', 'scat']),
 ('cat', ['act', 'cat']),
 ('cater',
  ['caret',
   'carte',
   'cater',
   'crate',
   'creat',
   'creta',
   'react',
   'recta',
   'trace']),
 ('cats', ['cast', 'scat']),
 ('cause', ['cause', 'sauce']),
 ('causes', ['causse']),
 ('ceas', ['case', 'esca']),
 ('cedars', ['sacred']),
 ('cedi', ['dice', 'iced']),
 ('cellar', ['caller', 'cellar', 'recall']),
 ('cents', ['scent']),
 ('cereus', ['ceruse', 'recuse', 'rescue', 'secure']),
 ('ceruse', ['ceruse', 'recuse', 'rescue', 'secure']),
 ('cesure', ['ceruse', 'recuse', 'rescue', 'secure']),
 ('charm', ['charm', 'march']),
 ('charmer', ['charmer', 'marcher', 'remarch']),
 ('charming', ['charming']),
 ('chase', ['chase']),
 ('cheating', ['cheating', 'teaching']),
 ('chetnik', ['kitchen', 'thicken']),
 ('chin', ['chin', 'inch']),
 ('chit', ['chit', 'itch']),
 ('chum', ['chum', 'much']),
 ('cion', ['cion', 'coin', 'icon']),
 ('citrus', ['citrus', 'rictus', 'rustic']),
 ('clam', ['calm', 'clam']),
 ('claro', ['calor', 'carol', 'claro', 'coral']),
 ('clay', ['acyl', 'clay', 'lacy']),
 ('cloud', ['cloud', 'could']),
 ('coal', ['alco', 'coal', 'cola', 'loca']),
 ('cocaine', ['cocaine', 'oceanic']),
 ('cod', ['cod', 'doc']),
 ('coin', ['cion', 'coin', 'icon']),
 ('cola', ['alco', 'coal', 'cola', 'loca']),
 ('comics', ['cosmic']),
 ('cone', ['cone', 'once']),
 ('coni', ['cion', 'coin', 'icon']),
 ('cool', ['cool', 'loco']),
 ('coral', ['calor', 'carol', 'claro', 'coral']),
 ('cork', ['cork', 'rock']),
 ('corset', ['corset', 'coster', 'escort', 'scoter', 'sector']),
 ('corvet', ['covert', 'vector']),
 ('cosmic', ['cosmic']),
 ('coster', ['corset', 'coster', 'escort', 'scoter', 'sector']),
 ('could', ['cloud', 'could']),
 ('covert', ['covert', 'vector']),
 ('crap', ['carp', 'crap']),
 ('crate',
  ['caret',
   'carte',
   'cater',
   'crate',
   'creat',
   'creta',
   'react',
   'recta',
   'trace']),
 ('crews', ['screw']),
 ('dab', ['bad', 'dab']),
 ('dad', ['add', 'dad']),
 ('dah', ['dah', 'dha', 'had']),
 ('dairy', ['dairy', 'diary', 'yaird']),
 ('dale', ['dale', 'deal', 'lade', 'lead']),
 ('dalets', ['desalt', 'salted']),
 ('dali', ['dali', 'dial', 'laid']),
 ('dam', ['dam', 'mad']),
 ('dance', ['dance', 'decan']),
 ('dare', ['ared', 'daer', 'dare', 'dear', 'read']),
 ('dashed', ['dashed', 'shaded']),
 ('dawn', ['dawn', 'wand']),
 ('deaf', ['deaf', 'fade']),
 ('deal', ['dale', 'deal', 'lade', 'lead']),
 ('dealer', ['dealer', 'leader', 'redeal', 'relade', 'relead']),
 ('dear', ['ared', 'daer', 'dare', 'dear', 'read']),
 ('dearer', ['reader', 'redare', 'reread']),
 ('death', ['death']),
 ('deaws', ['sawed']),
 ('declines', ['licensed', 'silenced']),
 ('decree', ['decree', 'recede']),
 ('deens', ['dense', 'needs']),
 ('defer', ['defer', 'freed']),
 ('deil', ['idle', 'lied']),
 ('delayer', ['delayer', 'layered', 'redelay']),
 ('deli', ['idle', 'lied']),
 ('deltas', ['desalt', 'salted']),
 ('denes', ['dense', 'needs']),
 ('dense', ['dense', 'needs']),
 ('denser', ['resend', 'sender']),
 ('desalt', ['desalt', 'salted']),
 ('deserver', ['deserver', 'reserved', 'reversed']),
 ('despair', ['despair', 'pardesi']),
 ('devote', ['devote']),
 ('dew', ['dew', 'wed']),
 ('dial', ['dali', 'dial', 'laid']),
 ('diaper', ['diaper', 'paired']),
 ('diapers', ['despair', 'pardesi']),
 ('diary', ['dairy', 'diary', 'yaird']),
 ('dice', ['dice', 'iced']),
 ('diel', ['idle', 'lied']),
 ('diet', ['diet', 'dite', 'edit', 'tide', 'tied']),
 ('dikes', ['skied']),
 ('dimple', ['dimple']),
 ('direr', ['drier', 'rider']),
 ('disease', ['disease', 'seaside']),
 ('disk', ['disk', 'skid']),
 ('dite', ['diet', 'dite', 'edit', 'tide', 'tied']),
 ('doc', ['cod', 'doc']),
 ('doen', ['done', 'node']),
 ('dog', ['dog', 'god']),
 ('dogs', ['dogs']),
 ('don', ['don', 'nod']),
 ('done', ['done', 'node']),
 ('doom', ['doom', 'mood']),
 ('dozen', ['dozen', 'zoned']),
 ('draw', ['draw', 'ward']),
 ('drawback', ['backward', 'drawback']),
 ('dreare', ['reader', 'redare', 'reread']),
 ('drier', ['drier', 'rider']),
 ('dune', ['dune', 'nude', 'unde']),
 ('dunite', ['dunite', 'united', 'untied']),
 ('dusty', ['dusty', 'study']),
 ('eager', ['agree', 'eager', 'eagre']),
 ('eagers', ['grease']),
 ('eagre', ['agree', 'eager', 'eagre']),
 ('eagres', ['grease']),
 ('ear', ['aer', 'are', 'ear', 'era', 'rea']),
 ('eard', ['ared', 'daer', 'dare', 'dear', 'read']),
 ('early', ['early', 'layer', 'relay']),
 ('earn', ['earn', 'near', 'rane']),
 ('earner', ['earner']),
 ('ears', ['arse', 'rase', 'sare', 'sear', 'sera']),
 ('earthy', ['earthy', 'hearty', 'yearth']),
 ('east', ['ates', 'east', 'eats', 'sate', 'seat', 'seta']),
 ('eastling', ['genitals', 'stealing']),
 ('eat', ['ate', 'eat', 'eta', 'tae', 'tea']),
 ('eath', ['haet', 'hate', 'heat']),
 ('eats', ['ates', 'east', 'eats', 'sate', 'seat', 'seta']),
 ('edit', ['diet', 'dite', 'edit', 'tide', 'tied']),
 ('eel', ['eel', 'lee']),
 ('egos', ['goes', 'sego']),
 ('eh', ['eh', 'he']),
 ('eild', ['idle', 'lied']),
 ('elbow', ['below', 'bowel', 'elbow']),
 ('elints', ['enlist', 'listen', 'silent', 'tinsel']),
 ('emit', ['emit', 'item', 'mite', 'time']),
 ('emits', ['metis', 'smite', 'stime', 'times']),
 ('emoter', ['meteor', 'remote']),
 ('enders', ['resend', 'sender']),
 ('enfiring', ['infringe', 'refining']),
 ('enlist', ['enlist', 'listen', 'silent', 'tinsel']),
 ('enlisted', ['enlisted', 'lintseed']),
 ('era', ['aer', 'are', 'ear', 'era', 'rea']),
 ('eras', ['arse', 'rase', 'sare', 'sear', 'sera']),
 ('eros', ['eros', 'rose', 'sero', 'sore']),
 ('escar', ['carse', 'caser', 'ceras', 'scare', 'scrae']),
 ('escort', ['corset', 'coster', 'escort', 'scoter', 'sector']),
 ('ester',
  ['ester',
   'estre',
   'reest',
   'reset',
   'steer',
   'stere',
   'stree',
   'terse',
   'tsere']),
 ('eta', ['ate', 'eat', 'eta', 'tae', 'tea']),
 ('etas', ['ates', 'east', 'eats', 'sate', 'seat', 'seta']),
 ('ether', ['ether', 'rethe', 'theer', 'there', 'three']),
 ('evil', ['evil', 'live', 'veil', 'vile', 'vlei']),
 ('evils', ['slive']),
 ('ewts', ['stew', 'west']),
 ('except', ['except', 'expect']),
 ('exist', ['exist', 'sixte']),
 ('exits', ['exist', 'sixte']),
 ('expect', ['except', 'expect']),
 ('face', ['face']),
 ('fade', ['deaf', 'fade']),
 ('failed', ['afield', 'defial']),
 ('faker', ['faker', 'freak']),
 ('fare', ['fare', 'fear', 'frae']),
 ('farmed', ['framed']),
 ('farming', ['farming', 'framing']),
 ('fast', ['fast', 'saft']),
 ('fat', ['aft', 'fat']),
 ('fate', ['atef', 'fate', 'feat']),
 ('fats', ['fast', 'saft']),
 ('fear', ['fare', 'fear', 'frae']),
 ('feat', ['atef', 'fate', 'feat']),
 ('feel', ['feel', 'flee']),
 ('feer', ['feer', 'free', 'reef']),
 ('felid', ['felid', 'field']),
 ('felt', ['felt', 'flet', 'left']),
 ('fere', ['feer', 'free', 'reef']),
 ('feta', ['atef', 'fate', 'feat']),
 ('fiber', ['bifer', 'brief', 'fiber']),
 ('fibre', ['bifer', 'brief', 'fiber']),
 ('field', ['felid', 'field']),
 ('filed', ['felid', 'field']),
 ('filer', ['filer', 'flier', 'lifer', 'rifle']),
 ('filets', ['itself', 'stifle']),
 ('filler', ['filler', 'refill']),
 ('finder', ['finder', 'friend', 'redfin', 'refind']),
 ('finer', ['finer', 'infer']),
 ('finger', ['finger', 'fringe']),
 ('fired', ['fired', 'fried']),
 ('fires', ['serif']),
 ('fist', ['fist', 'sift']),
 ('fitness', ['fitness']),
 ('fits', ['fist', 'sift']),
 ('flee', ['feel', 'flee']),
 ('flesh', ['flesh', 'shelf']),
 ('flied', ['felid', 'field']),
 ('flier', ['filer', 'flier', 'lifer', 'rifle']),
 ('fliest', ['itself', 'stifle']),
 ('flites', ['itself', 'stifle']),
 ('flog', ['flog', 'golf']),
 ('flow', ['flow', 'fowl', 'wolf']),
 ('flue', ['flue', 'fuel']),
 ('form', ['form', 'from']),
 ('former', ['former', 'reform']),
 ('forth', ['forth', 'froth']),
 ('fowl', ['flow', 'fowl', 'wolf']),
 ('frae', ['fare', 'fear', 'frae']),
 ('framed', ['framed']),
 ('framing', ['farming', 'framing']),
 ('freak', ['faker', 'freak']),
 ('free', ['feer', 'free', 'reef']),
 ('freed', ['defer', 'freed']),
 ('fried', ['fired', 'fried']),
 ('friend', ['finder', 'friend', 'redfin', 'refind']),
 ('fries', ['serif']),
 ('fringe', ['finger', 'fringe']),
 ('frise', ['serif']),
 ('from', ['form', 'from']),
 ('froth', ['forth', 'froth']),
 ('fuel', ['flue', 'fuel']),
 ('furs', ['surf']),
 ('gab', ['bag', 'gab']),
 ('gals', ['slag']),
 ('gaps', ['gasp']),
 ('garb', ['brag', 'garb', 'grab']),
 ('gas', ['gas', 'sag']),
 ('gasp', ['gasp']),
 ('gater', ['gater', 'grate', 'great', 'retag', 'targe']),
 ('geare', ['agree', 'eager', 'eagre']),
 ('geares', ['grease']),
 ('gel', ['gel', 'leg']),
 ('gelatins', ['genitals', 'stealing']),
 ('genitals', ['genitals', 'stealing']),
 ('geos', ['goes', 'sego']),
 ('girn', ['girn', 'grin', 'ring']),
 ('glare', ['argel', 'ergal', 'garle', 'glare', 'lager', 'large', 'regal']),
 ('god', ['dog', 'god']),
 ('gods', ['dogs']),
 ('goes', ['goes', 'sego']),
 ('golf', ['flog', 'golf']),
 ('grab', ['brag', 'garb', 'grab']),
 ('grate', ['gater', 'grate', 'great', 'retag', 'targe']),
 ('grease', ['grease']),
 ('great', ['gater', 'grate', 'great', 'retag', 'targe']),
 ('grin', ['girn', 'grin', 'ring']),
 ('grues', ['surge']),
 ('gulp', ['gulp', 'plug']),
 ('gum', ['gum', 'mug']),
 ('gunshot', ['gunshot', 'shotgun', 'uhtsong']),
 ('gust', ['gust', 'stug']),
 ('guts', ['gust', 'stug']),
 ('ha', ['ah', 'ha']),
 ('had', ['dah', 'dha', 'had']),
 ('haet', ['haet', 'hate', 'heat']),
 ('halls', ['shall']),
 ('halses', ['hassel', 'hassle']),
 ('hams', ['mash', 'samh', 'sham']),
 ('hangover', ['overhang']),
 ('harps', ['sharp', 'shrap']),
 ('has', ['ash', 'sah', 'sha']),
 ('hassel', ['hassel', 'hassle']),
 ('hassle', ['hassel', 'hassle']),
 ('hate', ['haet', 'hate', 'heat']),
 ('hated', ['death']),
 ('hay', ['hay', 'yah']),
 ('he', ['eh', 'he']),
 ('hearty', ['earthy', 'hearty', 'yearth']),
 ('heat', ['haet', 'hate', 'heat']),
 ('heater', ['heater', 'hereat', 'reheat']),
 ('heaters', ['thereas']),
 ('heir', ['heir', 'hire']),
 ('heirs', ['hirse', 'shier', 'shire']),
 ('hereat', ['heater', 'hereat', 'reheat']),
 ('hewn', ['hewn', 'when']),
 ('hikes', ['sheik']),
 ('hire', ['heir', 'hire']),
 ('hires', ['hirse', 'shier', 'shire']),
 ('ho', ['ho', 'oh']),
 ('hocks', ['shock']),
 ('hoes', ['hose', 'shoe']),
 ('hognuts', ['gunshot', 'shotgun', 'uhtsong']),
 ('hooks', ['shook']),
 ('hose', ['hose', 'shoe']),
 ('host', ['host', 'shot', 'tosh']),
 ('hots', ['host', 'shot', 'tosh']),
 ('houts', ['shout', 'south']),
 ('how', ['how', 'who']),
 ('howres', ['shower']),
 ('hubs', ['bush']),
 ('hug', ['hug', 'ugh']),
 ('hums', ['mush']),
 ('hustle', ['hustle', 'sleuth']),
 ('hustling', ['sunlight']),
 ('huts', ['shut', 'thus', 'tush']),
 ('iced', ['dice', 'iced']),
 ('icon', ['cion', 'coin', 'icon']),
 ('idea', ['aide', 'idea']),
 ('ideas', ['aside']),
 ('idle', ['idle', 'lied']),
 ('impart', ['armpit', 'impart']),
 ('impled', ['dimple']),
 ('imprints', ['misprint']),
 ('incest', ['encist', 'incest', 'insect', 'scient']),
 ('inch', ['chin', 'inch']),
 ('infer', ['finer', 'infer']),
 ('infests', ['fitness']),
 ('infringe', ['infringe', 'refining']),
 ('ink', ['ink', 'kin']),
 ('inks', ['inks', 'sink', 'skin']),
 ('inlets', ['enlist', 'listen', 'silent', 'tinsel']),
 ('ins', ['sin']),
 ('insect', ['encist', 'incest', 'insect', 'scient']),
 ('instar', ['instar', 'santir', 'strain']),
 ('insult', ['insult', 'sunlit', 'unlist', 'unslit']),
 ('itch', ['chit', 'itch']),
 ('item', ['emit', 'item', 'mite', 'time']),
 ('items', ['metis', 'smite', 'stime', 'times']),
 ('its', ['ist', 'its', 'sit']),
 ('itself', ['itself', 'stifle']),
 ('jest', ['jest']),
 ('jets', ['jest']),
 ('joiner', ['joiner', 'rejoin']),
 ('just', ['just']),
 ('juts', ['just']),
 ('kale', ['kale', 'lake', 'leak']),
 ('kebar', ['baker', 'brake', 'break']),
 ('keel', ['keel', 'kele', 'leek']),
 ('keels', ['skeel', 'sleek']),
 ('keen', ['keen', 'knee']),
 ('kids', ['disk', 'skid']),
 ('kills', ['skill']),
 ('kiln', ['kiln', 'link']),
 ('kin', ['ink', 'kin']),
 ('kins', ['inks', 'sink', 'skin']),
 ('kiss', ['kiss']),
 ('kisser', ['kisser', 'rekiss']),
 ('kitchen', ['kitchen', 'thicken']),
 ('knee', ['keen', 'knee']),
 ('koas', ['asok', 'soak', 'soka']),
 ('krises', ['kisser', 'rekiss']),
 ('lacy', ['acyl', 'clay', 'lacy']),
 ('lade', ['dale', 'deal', 'lade', 'lead']),
 ('laered', ['dealer', 'leader', 'redeal', 'relade', 'relead']),
 ('lager', ['argel', 'ergal', 'garle', 'glare', 'lager', 'large', 'regal']),
 ('lags', ['slag']),
 ('laid', ['dali', 'dial', 'laid']),
 ('lair', ['aril', 'lair', 'lari', 'liar', 'lira', 'rail', 'rial']),
 ('lake', ['kale', 'lake', 'leak']),
 ('lamb', ['balm', 'lamb']),
 ('lameness', ['lameness', 'maleness', 'maneless', 'nameless']),
 ('lames', ['amsel', 'mesal', 'samel']),
 ('lamp', ['lamp', 'palm']),
 ('lap', ['alp', 'lap', 'pal']),
 ('lapins', ['spinal']),
 ('laps', ['salp', 'slap']),
 ('lapse', ['lapse', 'salep', 'saple', 'sepal', 'slape', 'spale', 'speal']),
 ('large', ['argel', 'ergal', 'garle', 'glare', 'lager', 'large', 'regal']),
 ('lari', ['aril', 'lair', 'lari', 'liar', 'lira', 'rail', 'rial']),
 ('lases', ['salse']),
 ('lashes', ['hassel', 'hassle']),
 ('last', ['last', 'salt', 'slat']),
 ('lasted', ['desalt', 'salted']),
 ('lasting', ['lasting', 'salting', 'slating', 'staling']),
 ('late', ['atle', 'laet', 'late', 'leat', 'tael', 'tale', 'teal']),
 ('lats', ['last', 'salt', 'slat']),
 ('layer', ['early', 'layer', 'relay']),
 ('layered', ['delayer', 'layered', 'redelay']),
 ('layers', ['reslay', 'slayer']),
 ('laymen', ['meanly', 'namely']),
 ('layover', ['layover', 'overlay']),
 ('lays', ['slay']),
 ('lead', ['dale', 'deal', 'lade', 'lead']),
 ('leader', ['dealer', 'leader', 'redeal', 'relade', 'relead']),
 ('leak', ['kale', 'lake', 'leak']),
 ('leams', ['amsel', 'mesal', 'samel']),
 ('leap', ['leap', 'lepa', 'pale', 'peal', 'plea']),
 ('leaps', ['lapse', 'salep', 'saple', 'sepal', 'slape', 'spale', 'speal']),
 ('leared', ['dealer', 'leader', 'redeal', 'relade', 'relead']),
 ('learnt', ['altern', 'antler', 'learnt', 'rental', 'ternal']),
 ('leary', ['early', 'layer', 'relay']),
 ('leat', ['atle', 'laet', 'late', 'leat', 'tael', 'tale', 'teal']),
 ('lee', ['eel', 'lee']),
 ('leek', ['keel', 'kele', 'leek']),
 ('leeks', ['skeel', 'sleek']),
 ('left', ['felt', 'flet', 'left']),
 ('leg', ['gel', 'leg']),
 ('leke', ['keel', 'kele', 'leek']),
 ('lemon', ['lemon', 'melon', 'monel']),
 ('leper', ['leper', 'perle', 'repel']),
 ('lessened', ['needless', 'seldseen']),
 ('lessons', ['sonless']),
 ('levis', ['slive']),
 ('liar', ['aril', 'lair', 'lari', 'liar', 'lira', 'rail', 'rial']),
 ('license', ['license', 'selenic', 'silence']),
 ('licensed', ['licensed', 'silenced']),
 ('licks', ['slick']),
 ('lied', ['idle', 'lied']),
 ('lifer', ['filer', 'flier', 'lifer', 'rifle']),
 ('lime', ['lime', 'mile']),
 ('limes', ['limes', 'slime', 'smile']),
 ('limped', ['dimple']),
 ('link', ['kiln', 'link']),
 ('lino', ['lino', 'lion', 'loin', 'noil']),
 ('lintseed', ['enlisted', 'lintseed']),
 ('lion', ['lino', 'lion', 'loin', 'noil']),
 ('lippers', ['slipper']),
 ('lips', ['lisp', 'slip']),
 ('lira', ['aril', 'lair', 'lari', 'liar', 'lira', 'rail', 'rial']),
 ('lisp', ['lisp', 'slip']),
 ('list', ['list', 'silt', 'slit']),
 ('listen', ['enlist', 'listen', 'silent', 'tinsel']),
 ('listened', ['enlisted', 'lintseed']),
 ('listing', ['listing', 'silting']),
 ('lits', ['list', 'silt', 'slit']),
 ('live', ['evil', 'live', 'veil', 'vile', 'vlei']),
 ('lives', ['slive']),
 ('loca', ['alco', 'coal', 'cola', 'loca']),
 ('loco', ['cool', 'loco']),
 ('loin', ['lino', 'lion', 'loin', 'noil']),
 ('lookout', ['lookout', 'outlook']),
 ('looped', ['poodle']),
 ('loops', ['polos', 'sloop', 'spool']),
 ('loot', ['loot', 'tool']),
 ('lose', ['lose', 'sloe', 'sole']),
 ('lost', ['lost', 'lots', 'slot']),
 ('loto', ['loot', 'tool']),
 ('lots', ['lost', 'lots', 'slot']),
 ('loyal', ['alloy', 'loyal']),
 ('lump', ['lump', 'plum']),
 ('lure', ['lure', 'rule']),
 ('lured', ['duler', 'urled']),
 ('lures', ['sluer']),
 ('luring', ['ruling', 'urling']),
 ('ma', ['am', 'ma']),
 ('mace', ['acme', 'came', 'mace']),
 ('mad', ['dam', 'mad']),
 ('mainer', ['marine', 'remain']),
 ('maleness', ['lameness', 'maleness', 'maneless', 'nameless']),
 ('males', ['amsel', 'mesal', 'samel']),
 ('mane', ['amen', 'enam', 'mane', 'mean', 'name', 'nema']),
 ('maneless', ['lameness', 'maleness', 'maneless', 'nameless']),
 ('manors', ['ramson', 'ransom']),
 ('manures', ['surname']),
 ('map', ['amp', 'map', 'pam']),
 ('maples', ['sample']),
 ('maps', ['samp', 'spam']),
 ('mar', ['arm', 'mar', 'ram']),
 ('march', ['charm', 'march']),
 ('marcher', ['charmer', 'marcher', 'remarch']),
 ('marching', ['charming']),
 ('mare', ['mare', 'rame', 'ream']),
 ('marine', ['marine', 'remain']),
 ('marital', ['marital', 'martial']),
 ('marons', ['ramson', 'ransom']),
 ('mars', ['arms']),
 ('martial', ['marital', 'martial']),
 ('marts', ['smart', 'stram']),
 ('mash', ['mash', 'samh', 'sham']),
 ('mast', ['mast', 'stam']),
 ('mate', ['mate', 'meat', 'meta', 'tame', 'team']),
 ('mated', ['metad']),
 ('mates', ['steam', 'stema']),
 ('mating', ['mating']),
 ('mats', ['mast', 'stam']),
 ('meals', ['amsel', 'mesal', 'samel']),
 ('mean', ['amen', 'enam', 'mane', 'mean', 'name', 'nema']),
 ('meanly', ['meanly', 'namely']),
 ('meat', ['mate', 'meat', 'meta', 'tame', 'team']),
 ('meats', ['steam', 'stema']),
 ('melas', ['amsel', 'mesal', 'samel']),
 ('melon', ['lemon', 'melon', 'monel']),
 ('melts', ['smelt']),
 ('mesal', ['amsel', 'mesal', 'samel']),
 ('meta', ['mate', 'meat', 'meta', 'tame', 'team']),
 ('meteor', ['meteor', 'remote']),
 ('metis', ['metis', 'smite', 'stime', 'times']),
 ('metols', ['molest']),
 ('mile', ['lime', 'mile']),
 ('miles', ['limes', 'slime', 'smile']),
 ('misprint', ['misprint']),
 ('mite', ['emit', 'item', 'mite', 'time']),
 ('mites', ['metis', 'smite', 'stime', 'times']),
 ('mobbed', ['bombed']),
 ('moist', ['moist']),
 ('moits', ['moist']),
 ('molest', ['molest']),
 ('mono', ['mono', 'moon']),
 ('mood', ['doom', 'mood']),
 ('moon', ['mono', 'moon']),
 ('moor', ['moor', 'moro', 'room']),
 ('motels', ['molest']),
 ('much', ['chum', 'much']),
 ('mug', ['gum', 'mug']),
 ('murenas', ['surname']),
 ('mush', ['mush']),
 ('mutilate', ['mutilate', 'ultimate']),
 ('nags', ['sang', 'snag']),
 ('nails', ['sinal', 'slain', 'snail']),
 ('name', ['amen', 'enam', 'mane', 'mean', 'name', 'nema']),
 ('nameless', ['lameness', 'maleness', 'maneless', 'nameless']),
 ('namely', ['meanly', 'namely']),
 ('nap', ['nap', 'pan']),
 ('nare', ['earn', 'near', 'rane']),
 ('nat', ['ant', 'nat', 'tan']),
 ('nay', ['any', 'nay', 'yan']),
 ('near', ['earn', 'near', 'rane']),
 ('nearer', ['earner']),
 ('needless', ['needless', 'seldseen']),
 ('needs', ['dense', 'needs']),
 ('nema', ['amen', 'enam', 'mane', 'mean', 'name', 'nema']),
 ('neon', ['neon', 'none']),
 ('nest', ['nest', 'sent', 'sten']),
 ('net', ['net', 'ten']),
 ('nets', ['nest', 'sent', 'sten']),
 ('nevi', ['vein', 'vine']),
 ('nicest', ['encist', 'incest', 'insect', 'scient']),
 ('night', ['night', 'thing']),
 ('nights', ['nights']),
 ('nip', ['nip', 'pin']),
 ('nips', ['snip', 'spin']),
 ('nis', ['sin']),
 ('no', ['no', 'on']),
 ('nod', ['don', 'nod']),
 ('node', ['done', 'node']),
 ('noil', ['lino', 'lion', 'loin', 'noil']),
 ('none', ['neon', 'none']),
 ('normas', ['ramson', 'ransom']),
 ('not', ['not', 'ton']),
 ('note', ['note', 'tone']),
 ('noted', ['noted', 'toned']),
 ('noteless', ['noteless', 'toneless']),
 ('notices', ['contise', 'noetics', 'section']),
 ('noughts', ['gunshot', 'shotgun', 'uhtsong']),
 ('now', ['now', 'own', 'won']),
 ('nows', ['snow', 'sown']),
 ('nude', ['dune', 'nude', 'unde']),
 ('nudity', ['nudity', 'untidy']),
 ('nur', ['run', 'urn']),
 ('nurs', ['snur']),
 ('oaks', ['asok', 'soak', 'soka']),
 ('ocean', ['acone', 'canoe', 'ocean']),
 ('oceanic', ['cocaine', 'oceanic']),
 ('oh', ['ho', 'oh']),
 ('oils', ['silo', 'siol', 'soil', 'soli']),
 ('okas', ['asok', 'soak', 'soka']),
 ('oles', ['lose', 'sloe', 'sole']),
 ('omits', ['moist']),
 ('on', ['no', 'on']),
 ('once', ['cone', 'once']),
 ('opener', ['opener', 'reopen', 'repone']),
 ('opt', ['opt', 'pot', 'top']),
 ('option', ['option', 'potion']),
 ('opts', ['post', 'spot', 'stop', 'tops']),
 ('orbed', ['boder', 'orbed']),
 ('ores', ['eros', 'rose', 'sero', 'sore']),
 ('organist', ['orangist', 'organist', 'roasting', 'signator']),
 ('oriental', ['oriental', 'relation']),
 ('ought', ['ought', 'tough']),
 ('oughts', ['sought']),
 ('ours', ['ours', 'sour']),
 ('outlook', ['lookout', 'outlook']),
 ('overhang', ['overhang']),
 ('overlay', ['layover', 'overlay']),
 ('own', ['now', 'own', 'won']),
 ('owns', ['snow', 'sown']),
 ('owt', ['tow', 'two', 'wot']),
 ('pace', ['cape', 'cepa', 'pace']),
 ('packer', ['packer', 'repack']),
 ('padle', ['padle', 'paled', 'pedal', 'plead']),
 ('painter', ['painter', 'pertain', 'repaint']),
 ('paired', ['diaper', 'paired']),
 ('pal', ['alp', 'lap', 'pal']),
 ('pale', ['leap', 'lepa', 'pale', 'peal', 'plea']),
 ('paled', ['padle', 'paled', 'pedal', 'plead']),
 ('pales', ['lapse', 'salep', 'saple', 'sepal', 'slape', 'spale', 'speal']),
 ('palest', ['pastel', 'septal', 'staple']),
 ('palets', ['pastel', 'septal', 'staple']),
 ('palm', ['lamp', 'palm']),
 ('pals', ['salp', 'slap']),
 ('pam', ['amp', 'map', 'pam']),
 ('pams', ['samp', 'spam']),
 ('pan', ['nap', 'pan']),
 ('panel', ['panel', 'penal', 'plane']),
 ('pardie', ['diaper', 'paired']),
 ('pare', ['aper', 'pare', 'pear', 'rape', 'reap']),
 ('parks', ['spark']),
 ('partim', ['armpit', 'impart']),
 ('parts', ['spart', 'sprat', 'strap', 'traps']),
 ('pass', ['pass']),
 ('pastel', ['pastel', 'septal', 'staple']),
 ('pat', ['apt', 'pat', 'tap']),
 ('pate', ['pate', 'peat', 'tape', 'teap']),
 ('pay', ['pay', 'pya', 'yap']),
 ('pea', ['ape', 'pea']),
 ('peaks', ['sapek', 'speak']),
 ('peal', ['leap', 'lepa', 'pale', 'peal', 'plea']),
 ('peals', ['lapse', 'salep', 'saple', 'sepal', 'slape', 'spale', 'speal']),
 ('pear', ['aper', 'pare', 'pear', 'rape', 'reap']),
 ('peat', ['pate', 'peat', 'tape', 'teap']),
 ('pedal', ['padle', 'paled', 'pedal', 'plead']),
 ('pela', ['leap', 'lepa', 'pale', 'peal', 'plea']),
 ('pelas', ['lapse', 'salep', 'saple', 'sepal', 'slape', 'spale', 'speal']),
 ('pelmas', ['sample']),
 ('peltas', ['pastel', 'septal', 'staple']),
 ('pelts', ['slept', 'spelt', 'splet']),
 ('penal', ['panel', 'penal', 'plane']),
 ('penster', ['penster', 'present', 'serpent', 'strepen']),
 ('per', ['per', 'rep']),
 ('pereon', ['opener', 'reopen', 'repone']),
 ('peri', ['peri', 'pier', 'ripe']),
 ('perone', ['opener', 'reopen', 'repone']),
 ('pertain', ['painter', 'pertain', 'repaint']),
 ('pest', ['pest', 'sept', 'spet', 'step']),
 ('petals', ['pastel', 'septal', 'staple']),
 ('pets', ['pest', 'sept', 'spet', 'step']),
 ('pier', ['peri', 'pier', 'ripe']),
 ('pills', ['spill']),
 ('pin', ['nip', 'pin']),
 ('pinots', ['piston']),
 ('pins', ['snip', 'spin']),
 ('pintos', ['piston']),
 ('piston', ['piston']),
 ('pit', ['pit', 'tip']),
 ('pitons', ['piston']),
 ('pits', ['pist', 'spit']),
 ('plains', ['spinal']),
 ('plane', ['panel', 'penal', 'plane']),
 ('plaste', ['pastel', 'septal', 'staple']),
 ('plates', ['pastel', 'septal', 'staple']),
 ('plea', ['leap', 'lepa', 'pale', 'peal', 'plea']),
 ('plead', ['padle', 'paled', 'pedal', 'plead']),
 ('pleas', ['lapse', 'salep', 'saple', 'sepal', 'slape', 'spale', 'speal']),
 ('pleats', ['pastel', 'septal', 'staple']),
 ('plena', ['panel', 'penal', 'plane']),
 ('plug', ['gulp', 'plug']),
 ('plum', ['lump', 'plum']),
 ('points', ['piston']),
 ('polos', ['polos', 'sloop', 'spool']),
 ('poodle', ['poodle']),
 ('pooled', ['poodle']),
 ('pools', ['polos', 'sloop', 'spool']),
 ('pore', ['pore', 'rope']),
 ('pores', ['poser', 'prose', 'ropes', 'spore']),
 ('ports', ['sport', 'strop']),
 ('poser', ['poser', 'prose', 'ropes', 'spore']),
 ('post', ['post', 'spot', 'stop', 'tops']),
 ('postin', ['piston']),
 ('postman', ['postman', 'topsman']),
 ('pot', ['opt', 'pot', 'top']),
 ('potins', ['piston']),
 ('potion', ['option', 'potion']),
 ('pots', ['post', 'spot', 'stop', 'tops']),
 ('praised', ['despair', 'pardesi']),
 ('prats', ['spart', 'sprat', 'strap', 'traps']),
 ('prays', ['raspy', 'spary', 'spray']),
 ('pre', ['per', 'rep']),
 ('present', ['penster', 'present', 'serpent', 'strepen']),
 ('printer', ['printer', 'reprint']),
 ('pronto', ['pronto', 'proton']),
 ('prose', ['poser', 'prose', 'ropes', 'spore']),
 ('prost', ['sport', 'strop']),
 ('proton', ['pronto', 'proton']),
 ('pya', ['pay', 'pya', 'yap']),
 ('quiet', ['quiet', 'quite']),
 ('quite', ['quiet', 'quite']),
 ('race', ['acre', 'care', 'crea', 'race']),
 ('races', ['carse', 'caser', 'ceras', 'scare', 'scrae']),
 ('racket', ['racket', 'retack', 'tacker']),
 ('rade', ['ared', 'daer', 'dare', 'dear', 'read']),
 ('ragee', ['agree', 'eager', 'eagre']),
 ('ragees', ['grease']),
 ('raginis', ['raising']),
 ('rail', ['aril', 'lair', 'lari', 'liar', 'lira', 'rail', 'rial']),
 ('raising', ['raising']),
 ('ram', ['arm', 'mar', 'ram']),
 ('rams', ['arms']),
 ('ramson', ['ramson', 'ransom']),
 ('ransom', ['ramson', 'ransom']),
 ('rape', ['aper', 'pare', 'pear', 'rape', 'reap']),
 ('rare', ['rare', 'rear']),
 ('rase', ['arse', 'rase', 'sare', 'sear', 'sera']),
 ('raspy', ['raspy', 'spary', 'spray']),
 ('rast', ['sart', 'star', 'stra', 'tars', 'tsar']),
 ('rat', ['art', 'rat', 'tar', 'tra']),
 ('rats', ['sart', 'star', 'stra', 'tars', 'tsar']),
 ('raw', ['raw', 'war']),
 ('rayle', ['early', 'layer', 'relay']),
 ('rayles', ['reslay', 'slayer']),
 ('react',
  ['caret',
   'carte',
   'cater',
   'crate',
   'creat',
   'creta',
   'react',
   'recta',
   'trace']),
 ('read', ['ared', 'daer', 'dare', 'dear', 'read']),
 ('reader', ['reader', 'redare', 'reread']),
 ('realist', ['realist', 'saltier']),
 ('ream', ['mare', 'rame', 'ream']),
 ('rean', ['earn', 'near', 'rane']),
 ('reap', ['aper', 'pare', 'pear', 'rape', 'reap']),
 ('rear', ['rare', 'rear']),
 ('reared', ['reader', 'redare', 'reread']),
 ('rebuild', ['builder', 'rebuild']),
 ('recall', ['caller', 'cellar', 'recall']),
 ('recede', ['decree', 'recede']),
 ('recital', ['article', 'recital']),
 ('recitals', ['altrices', 'selictar']),
 ('recta',
  ['caret',
   'carte',
   'cater',
   'crate',
   'creat',
   'creta',
   'react',
   'recta',
   'trace']),
 ('rectos', ['corset', 'coster', 'escort', 'scoter', 'sector']),
 ('recuse', ['ceruse', 'recuse', 'rescue', 'secure']),
 ('recused', ['seducer']),
 ('redeal', ['dealer', 'leader', 'redeal', 'relade', 'relead']),
 ('redear', ['reader', 'redare', 'reread']),
 ('redfin', ['finder', 'friend', 'redfin', 'refind']),
 ('reduces', ['seducer']),
 ('reearn', ['earner']),
 ('reef', ['feer', 'free', 'reef']),
 ('reest',
  ['ester',
   'estre',
   'reest',
   'reset',
   'steer',
   'stere',
   'stree',
   'terse',
   'tsere']),
 ('refed', ['defer', 'freed']),
 ('refill', ['filler', 'refill']),
 ('refind', ['finder', 'friend', 'redfin', 'refind']),
 ('refining', ['infringe', 'refining']),
 ('reform', ['former', 'reform']),
 ('regal', ['argel', 'ergal', 'garle', 'glare', 'lager', 'large', 'regal']),
 ('reheat', ['heater', 'hereat', 'reheat']),
 ('reheats', ['thereas']),
 ('reifs', ['serif']),
 ('reins', ['reins', 'resin', 'rinse', 'risen', 'serin', 'siren']),
 ('reird', ['drier', 'rider']),
 ('reists', ['resist', 'restis', 'sister']),
 ('rejoin', ['joiner', 'rejoin']),
 ('relation', ['oriental', 'relation']),
 ('relay', ['early', 'layer', 'relay']),
 ('relayed', ['delayer', 'layered', 'redelay']),
 ('relays', ['reslay', 'slayer']),
 ('remain', ['marine', 'remain']),
 ('remote', ['meteor', 'remote']),
 ('rental', ['altern', 'antler', 'learnt', 'rental', 'ternal']),
 ('rentals', ['saltern', 'starnel', 'sternal']),
 ('reopen', ['opener', 'reopen', 'repone']),
 ('rep', ['per', 'rep']),
 ('repack', ['packer', 'repack']),
 ('repaid', ['diaper', 'paired']),
 ('repaint', ['painter', 'pertain', 'repaint']),
 ('repel', ['leper', 'perle', 'repel']),
 ('repents', ['penster', 'present', 'serpent', 'strepen']),
 ('repins', ['respin', 'sniper']),
 ('repo', ['pore', 'rope']),
 ('repone', ['opener', 'reopen', 'repone']),
 ('repos', ['poser', 'prose', 'ropes', 'spore']),
 ('reprint', ['printer', 'reprint']),
 ('reread', ['reader', 'redare', 'reread']),
 ('rescue', ['ceruse', 'recuse', 'rescue', 'secure']),
 ('rescued', ['seducer']),
 ('resell', ['resell', 'seller']),
 ('resend', ['resend', 'sender']),
 ('reserve', ['reserve', 'resever', 'reverse', 'severer']),
 ('reserved', ['deserver', 'reserved', 'reversed']),
 ('reset',
  ['ester',
   'estre',
   'reest',
   'reset',
   'steer',
   'stere',
   'stree',
   'terse',
   'tsere']),
 ('reshow', ['shower']),
 ('resin', ['reins', 'resin', 'rinse', 'risen', 'serin', 'siren']),
 ('resist', ['resist', 'restis', 'sister']),
 ('resits', ['resist', 'restis', 'sister']),
 ('retack', ['racket', 'retack', 'tacker']),
 ('retag', ['gater', 'grate', 'great', 'retag', 'targe']),
 ('retails', ['realist', 'saltier']),
 ('retes',
  ['ester',
   'estre',
   'reest',
   'reset',
   'steer',
   'stere',
   'stree',
   'terse',
   'tsere']),
 ('rethink', ['rethink', 'thinker']),
 ('retrain', ['arterin', 'retrain', 'terrain', 'trainer']),
 ('retund', ['runted', 'tunder', 'turned']),
 ('reveres', ['reserve', 'resever', 'reverse', 'severer']),
 ('reverse', ['reserve', 'resever', 'reverse', 'severer']),
 ('reversed', ['deserver', 'reserved', 'reversed']),
 ('review', ['review', 'viewer']),
 ('rhies', ['hirse', 'shier', 'shire']),
 ('rial', ['aril', 'lair', 'lari', 'liar', 'lira', 'rail', 'rial']),
 ('rictus', ['citrus', 'rictus', 'rustic']),
 ('rider', ['drier', 'rider']),
 ('rifle', ['filer', 'flier', 'lifer', 'rifle']),
 ('rines', ['reins', 'resin', 'rinse', 'risen', 'serin', 'siren']),
 ('ring', ['girn', 'grin', 'ring']),
 ('rinse', ['reins', 'resin', 'rinse', 'risen', 'serin', 'siren']),
 ('ripe', ['peri', 'pier', 'ripe']),
 ('ripens', ['respin', 'sniper']),
 ('ripples', ['slipper']),
 ('risen', ['reins', 'resin', 'rinse', 'risen', 'serin', 'siren']),
 ('rite', ['iter', 'reit', 'rite', 'tier', 'tire']),
 ('rival', ['rival', 'viral']),
 ('roasting', ['orangist', 'organist', 'roasting', 'signator']),
 ('robed', ['boder', 'orbed']),
 ('robes', ['boser', 'brose', 'sober']),
 ('rock', ['cork', 'rock']),
 ('roes', ['eros', 'rose', 'sero', 'sore']),
 ('romans', ['ramson', 'ransom']),
 ('room', ['moor', 'moro', 'room']),
 ('rope', ['pore', 'rope']),
 ('ropes', ['poser', 'prose', 'ropes', 'spore']),
 ('rose', ['eros', 'rose', 'sero', 'sore']),
 ('rout', ['rout', 'toru', 'tour']),
 ('rowdier', ['worried']),
 ('ruby', ['bury', 'ruby']),
 ('rule', ['lure', 'rule']),
 ('ruled', ['duler', 'urled']),
 ('rules', ['sluer']),
 ('ruling', ['ruling', 'urling']),
 ('run', ['run', 'urn']),
 ('runs', ['snur']),
 ('runted', ['runted', 'tunder', 'turned']),
 ('runts', ['snurt', 'turns']),
 ('rust', ['rust']),
 ('rustic', ['citrus', 'rictus', 'rustic']),
 ('rusts', ['truss']),
 ('ruts', ['rust']),
 ('sack', ['cask', 'sack']),
 ('sacred', ['sacred']),
 ('sag', ['gas', 'sag']),
 ('saint', ['saint', 'satin', 'stain']),
 ('sairing', ['raising']),
 ('salep', ['lapse', 'salep', 'saple', 'sepal', 'slape', 'spale', 'speal']),
 ('sales', ['salse']),
 ('salesmen', ['lameness', 'maleness', 'maneless', 'nameless']),
 ('salp', ['salp', 'slap']),
 ('salse', ['salse']),
 ('salt', ['last', 'salt', 'slat']),
 ('salted', ['desalt', 'salted']),
 ('saltern', ['saltern', 'starnel', 'sternal']),
 ('saltier', ['realist', 'saltier']),
 ('salting', ['lasting', 'salting', 'slating', 'staling']),
 ('saltire', ['realist', 'saltier']),
 ('samel', ['amsel', 'mesal', 'samel']),
 ('samp', ['samp', 'spam']),
 ('sample', ['sample']),
 ('sang', ['sang', 'snag']),
 ('santir', ['instar', 'santir', 'strain']),
 ('saps', ['pass']),
 ('sate', ['ates', 'east', 'eats', 'sate', 'seat', 'seta']),
 ('satem', ['steam', 'stema']),
 ('satin', ['saint', 'satin', 'stain']),
 ('sauce', ['cause', 'sauce']),
 ('sauces', ['causse']),
 ('save', ['save', 'vase']),
 ('saw', ['saw', 'swa', 'was']),
 ('sawed', ['sawed']),
 ('scab', ['scab']),
 ('scan', ['scan']),
 ('scar', ['scar']),
 ('scare', ['carse', 'caser', 'ceras', 'scare', 'scrae']),
 ('scared', ['sacred']),
 ('scat', ['cast', 'scat']),
 ('scent', ['scent']),
 ...]

The complexity of this algorithm is O(M * KlogK + N), much much faster!

In [ ]:

In [ ]: