I'm new to Python and this was written and posted by someone else on another site as a tutorial for a word unscrambler. I thought it was well written and liked the explanations but I tried to use it but keep getting an error message:
line 27, in <module>
letters = list(wordlist[x])
IndexError: list index out of range
Can someone explain this to me and tell me how to correct it? Here's the code below. Written by '15feb93':
import string
dictString = open('wordlist.txt', 'U').read()
dictList = dictString.split('\n')
x = 0
newDict = ''
while x != 1275:
letters = list(dictList[x])
letters.sort()
abcString = str(letters).strip(" [] ").replace(',', '').replace("\'", '').replace(' ', '')
newDict += abcString + '\n'
x += 1
abcDictList = newDict.split('\n')
x = 0
wordstring = open('scrambled.txt', 'U').read()
wordstring = wordstring.replace('#', '').replace('\t', '').replace(' ', '').replace(',', '\n')
wordlist = wordstring.split('\n')
newWord = ''
while x != 10:
letters = list(wordlist[x])
letters.sort()
abcString = str(letters).strip(" [] ").replace(',', '').replace("\'", '').replace(' ', '')
newWord += abcString + '\n'
x += 1
abcWordList = newWord.split('\n')
x = 0
Solution = ''
while x != 10:
y = 0
while y != 1275:
if abcWordList[x] == abcDictList[y]:
break
else:
y += 1
Solution += dictlist[y] + ','
x += 1
solutionWrite = open('solution.txt', 'w')
solutionWrite.write(Solution)