# wordgame.py words = [ line.strip() for line in open( 'ospd.txt' ) ] words5 = [ line.strip() for line in open( 'ospd.txt' ) if len( line ) == 6 ] # note each five-letter word will be len() six due to '\n' at the end words2 = [ x for x in words if len( x ) == 2 ] words4 = [ x for x in words if len( x ) == 4 ] # etc. def generatePermutations( word ): if len( word ) <= 1: yield word else: for p in generatePermutations( word[1:] ): for i in range( len( p ) + 1 ): yield p[:i] + word[0] + p[i:] word = 'spot' generatePermutations( word ) # we'll revisit this next class...