Hey guys I finally got my word unscrambler working the other day, now I fire it up with same code same everything and for some reason getting double output from a list that shouldn't be. So if someone could either look this over and find a problem or maybe do a test run on their computer and let me know if something is currupt somehow on my system that would be great to. I just can't tell if its the code or my computer or the interprater that is messed up. I'll attach some sample files to use to run it. Thanks again.
Here is the code.
#decode scrambled word from a word list in 30 sec or less.
wordlist = []
possible = []
matches = []
thelist = []
myvar = -1
c = -1
p = -1
wordlistfile = open('C:\\Documents and Settings\\William\\Desktop\\wordlist\\wordlist.txt', 'r')
possiblefile = open('C:\\Documents and Settings\\William\\Desktop\\possible.txt', 'r')
#add file contents to lists.
while p < 9:
i = -1
p = p + 1
print p
for line in wordlistfile:
wordlist.append(line.strip())
for line in possiblefile:
possible.append(line.strip())
#match length of words to narrow possible matches
for line in wordlist:
i = i + 1
if len(wordlist[i]) == len(possible[p]):
matches.append(wordlist[i])
#narrow further by checking for instances of charecters
word = possible[p]
x = len(matches)
while c < x:
c = c + 1
for letter in word:
if c == x:
break
if not letter in matches[c]:
del matches[c]
x = x - 1
#start rearanging word.
word = word.strip().lower()
for pos in matches:
tmp1 = []
tmp2 = []
tmp1 = list(pos.lower().strip())
tmp2 = list(word)
tmp1.sort()
tmp2.sort()
if tmp1 == tmp2:
print p
myvar = myvar + 1
thelist.append(pos)
if myvar == 10:
print(thelist[myvar])
break
elif myvar < 9:
print(thelist[myvar] + ', ')
wordlistfile.close()
possiblefile.close()