| newCharDict = {'a':0,'b':0,'c':0,'d':0,'e':0,'f':0,'g':0,'h':0,'i':0,'j':0,'k':0,'l':0,'m':0,'n':0,'o':0,'p':0,'q':0,'r':0,'s':0,'t':0,'u':0,'v':0,'w':0,'x':0,'y':0,'z':0, 'empty':0 } | |
| goodchars = [] | |
| badchars = [] | |
| #with open('./wordList.txt') as f: | |
| with open('/usr/share/dict/words') as f: | |
| wordList=f.read().splitlines() | |
| wordList = [x.lower() for x in wordList] | |
| newWords = wordList | |
| print "No of words:", len(newWords) | |
| charDict = newCharDict | |
| while True : | |
| # newWords = wordList | |
| bestChar = 'empty' | |
| for key in charDict : | |
| charDict[key] = 0 | |
| userinput = raw_input("letters, use - for empty: ") | |
| words = [] | |
| for word in newWords : | |
| if len(word) == len(userinput) : | |
| words.append(word) | |
| newWords = words | |
| for word in newWords : | |
| for i in range(len(word)) : | |
| if word[i] not in list(charDict.keys()) : | |
| try: | |
| newWords.remove(word) | |
| except Exception as e: | |
| print word | |
| print e | |
| pass | |
| if (userinput[i] != word[i]) and (userinput[i] != '-') : | |
| try : | |
| newWords.remove(word) | |
| except : | |
| pass | |
| if (userinput[i] == '-'): | |
| try : | |
| charDict[word[i]] = charDict[word[i]] + 1 | |
| except: | |
| pass | |
| for char in charDict : | |
| if charDict[char] > charDict[bestChar]: | |
| bestChar = char | |
| print "score:", charDict[bestChar], " bestchar:", bestChar | |
| charDict.pop(bestChar) | |
| # print charDict | |
| print "amount of words considered: ", len(newWords) | |
| print "-"*80 | |
| print '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment