[Tutor] Comparing lines in two files, writing result into a t
Wed Apr 23 11:20:03 2003
> I have two files, file1.txt and file 2. txt, each containing
> numbers. I want to compare the numbers in the files and put
> an asterisk at the end of the numbers that match, writing the
> result into a third file
> I've tried various combinations of opening the files and 'if'
> nests, but I can't seem to get it right. Any hints on what
> structure to use. Thanks in advance.
Hints? Dictionary! Use a dictionary to record the numbers in the first file.
Then compare the numbers in the second file, giving a meaningful value to
those that are duplicated and just recording the others. You now have enough
information to write your third file.
> I have two files, file1 and file2. I want to print the first
> line from file1, then the first line from file2, then the second
> line from file 1, then the second line from file 2, etc.
Not sure if this was yours also, but as another hint: check your version of
python. If it's 2.0 or greater, check the Library Reference for the built-in