I'm reading in a text file and I am trying to erase everything except the first word on each line. So, what I am doing after reading the text file is splitting it with space as the delimetre and then storing the words in an array.
Now, my plan with the array is to save the first word, what is at location 0 as a new line in a text file. Then I will have a text file with only the first words of my original file.
What I am having trouble with is writing the array[0] to a new line in a new text file and then saving that text file. How can I do that in Python 2.7 ?
Here is my code so far. The part that I don't know how to do is the part that is just a comment.
import sys
import re
read_file = open(sys.argv[1]) #reads a file
for i in iter(read_file): #reads through all the lines one by one
k = i.split(' ') #splits it by space
#save k[0] as new line in a .txt file
#save newly made text file
#close file operations
read_file.close()
read_filewill be an iterable so no need foriter().