Right now the main thing wrong are all the missing indentation that Python uses to block code.
It would be nice to know what 'wordlist.txt' looks like.
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
So your file has one word per line?
The missing indentations are most like fault of your code editor.
What editor are you using?
bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
I don't have your files available to test this, but I added try/excepts just in case you have less data in your files than you expect ...
import string
dictString = open('wordlist.txt', 'U').read()
dictList = dictString.split('\n')
x = 0
newDict = ''
while x != 1275:
try:
letters = list(dictList[x])
except IndexError:
break
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:
try:
letters = list(wordlist[x])
except IndexError:
break
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)
Somehow your code lost all its indentations, I had to guess them back in manually, hope they are okay. Give it a try!
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
Are you trying to unscramble words?
vegaseat
DaniWeb's Hypocrite
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
You might want to try
import string
file_pointer= open('wordlist.txt', 'U')
dictList = file_pointer.readlines()
file_pointer.close()
x = 0
newDict = ''
stop = len(dictList)
while x < stop:
## you could also use "for each_rec in dictList :"
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714