beginner's question

Hadi hadi at nojunk.com.au
Fri May 14 12:38:17 EDT 2004


Sean,

I appreciate for your help. Your script works fine. I have one last
question.
What do I have to modify on the script, so the script will work for more
than one line?
Because the file-1 has about 500 lines.
This is for my Machine Learning assignment which I use this for the Naive
Bayes classifier for the spam mail classification.
Thank you again and I would appreciate very much one more help from you.

Regards,
Halit

your script:

exicon = ["our", "halit", "of", "words", "to", "be", "compared"]

# open the source and destination files
src = file("file-1.txt")           # open for reading
dst = file("file-2.txt", 'w')     # open for writing

# Hadi: does file1 contain one or more lines? This only works for one line.
# For more lines, you'll need to do further processing ...
#
# Make a list of the words in src. We split the line at each comma, and
# remove any excess whitespace from around the word
words = [w.strip() for w in src.readline().split(',')]

# Now we see if the words are in our list and write the results to dst
for w in words:
 dst.write("%s, "%(w in lexicon))

# Python will eventually close the files for you, or you can do it
explicitly
src.close()
dst.close()





More information about the Python-list mailing list