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

1452 lines
60 KiB
Plaintext

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