Skip to content

Instantly share code, notes, and snippets.

@aphahn aphahn/
Created Dec 24, 2010

What would you like to do?
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:
prefixes = None
for set in suffixes.itervalues():
if prefixes is None:
prefixes = set
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
You can’t perform that action at this time.