Hey guys,
I been working on a small project I found on another forum. It's supposed to decode scrambled word from a word list in 30 sec or less. Well I'm pretty noobish so my method might not be all that great, but I'm giving it a go and learning quite a bit along the way. Anyways I figured out how to get the information from the files and put it into lists, but the problem I'm facing now is that the copied lists carry over the \n with them, which I need to get rid of. Any ideas or suggestions would be awsome thanks.

here is the code:

#decode scrambled word from a word list in 30 sec or less.
wordlist = []
possible = []
matches = []
wordlist = []
i = -1
p = 0
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.
for line in wordlistfile:
    wordlist.append(line)
for line in possiblefile:
    possible.append(line)

for line in wordlist:
    i = i + 1
    if len(wordlist[i]) == len(possible[p]):
        matches.append(wordlist[i])
print matches

        
    

wordlistfile.close()
possiblefile.close()

Something like this will do:

for line in wordlistfile:
    wordlist.append(line.strip())

Thanks works like a charm. What exactly does strip() do though? Just wondering.

I see thanks, that is one of the few items in the library that I can actually understand, lol. I'm not very good with the terminology so it always sounds so cryptic in the definitions.;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.