Create a gist now

Instantly share code, notes, and snippets.

A fun little tool that, given suffixes and a wordlist, prints words that end in those suffixes
#!/usr/bin/env python
import sys
def to_set(collection):
return "{" + ",".join(collection) + "}"
suffixes = {}
for suffix in sys.argv[1:-1]:
suffixes[suffix] = set()
filename = sys.argv[-1]
with open(filename, 'r') as wordlist:
for line in wordlist:
word = line.strip()
for suffix, set in suffixes.iteritems():
if word.endswith(suffix):
prefix = word[:-len(suffix)]
if prefix:
set.add(prefix)
prefixes = None
for set in suffixes.itervalues():
if prefixes is None:
prefixes = set
else:
prefixes &= set
print to_set(prefixes) + to_set(suffixes.keys())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment