Python Advanced #9 - Reading Two Columns from a Justified Text File and Writing to a New File

In this post, we start with a justified text file as shown below.  This file is titled sampletext.txt.


Our objective is to extract the date along with the values in the last column and to write those values to a different text file.  We do this by using the code below.

We first open the file and then read each line.  As each line is read, we extract the date and the values in the last column and append them to lists named vals1 and vals2.  Once that is completed, we create a new text file titled twocoloutput.txt and write each pair of values in the lists to this file with each pair of values appearing on a separate line.



The results of this program are shown below.


Comments