Created
December 7, 2011 12:20
-
-
Save alexalemi/1442608 to your computer and use it in GitHub Desktop.
Reddit Python Quiz 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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