Skip to content

Instantly share code, notes, and snippets.

@alexalemi
Created December 7, 2011 12:20
Show Gist options
  • Save alexalemi/1442608 to your computer and use it in GitHub Desktop.
Save alexalemi/1442608 to your computer and use it in GitHub Desktop.
Reddit Python Quiz 1
#! /usr/bin/env python
import sys, itertools
def wordchecker(dictfile,*lets):
""" Find the longest words made up of lets that are contained in dictfile """
dictionary = set( w.rstrip() for w in open(dictfile,'r')) #SpellChecker(['ospd.txt'])
def allwords(lets):
""" Return a generator of the longest words """
breakout = False
for n in range(len(lets)+1,0,-1):
for perm in itertools.permutations(lets,n):
word = ''.join(perm)
if word in dictionary:
yield word
breakout = True
if breakout:
break
return list(allwords(lets))
if __name__ == "__main__":
print wordchecker(sys.argv[1],*sys.argv[2:])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment