| | |
importing files to lists
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 20
Reputation:
Solved Threads: 0
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:
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:
Python Syntax (Toggle Plain Text)
#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:
python Syntax (Toggle Plain Text)
for line in wordlistfile: wordlist.append(line.strip())
Should you find Irony, you can keep her!
![]() |
Similar Threads
Other Threads in the Python Forum
- Previous Thread: Deploying a Python Service on Axis2
- Next Thread: part 2->How to find which menu option is selected
| Thread Tools | Search this Thread |
accessdenied apache application argv array beginner book builtin change chmod converter countpasswordentry curved dan08 dictionary dynamic edit enter examples file filename float format function gui homework import inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysql mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pyopengl pysimplewizard python random recursion redirect remote reverse scrolledtext session simple smtp software sprite statictext string strings syntax table tennis terminal text textarea thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable windows wordgame wxpython






