beginner's question

Peter Hansen peter at engcorp.com
Fri May 14 08:32:59 EDT 2004


Hadi wrote:

> I have two files and the array that contains 20 words in it.
> I'm trying to write python script that suppose achieve the following:
> -Open file-1, read the line that contains 20 words separated with commas
> -Compare each word with words in the array
> -Open file-2
> -if the word appears in the array write 'true' in file-2
> -if not write 'false'
> -repeat this for every line in the file-1
> 
> so, two file will be identical in terms of number of lines and number of
> words in each line.
> However, file-2 will only contain wods 'true' and 'false'.
> 
> Can anyone give some example or point me to som useful web sites please.

Can you post some sample code that you've written to show that you've
actually tried by yourself first?  That will also give us a starting
point in helping you.

Otherwise we're likely to be spoonfeeding you answers to your homework
assignment.  Presumably you have already learned some basic programming
in class and are supposed to be trying to apply that learning in this
exercise?

Hints: How do you open a file in Python and read lines from it?  (see
the tutorial online at www.python.org)  How do you define an "array"
in Python?  (see tutorial again, looking at dictionaries)  How do you
write a loop in Python?  (use the 'for' or 'while' keywords, depending
on what exactly you want to do: see the tutorial for examples)

-Peter



More information about the Python-list mailing list