Full script essentially opens a txt file with three columns separated by a whitespace and saves it to a list words
with open(filename) as f:
words = f.read().split()
Every third item is deleted from the list starting from position 2 using: del words[2::3]
The next step I would like to add is writing to the same filename with two of the three columns (or every two items in words), space them out and then create a new line in a text file:
('list_item1' + ' ' + 'list_item2' + '/n'), ('list_item3' + ' ' + 'list_item4' + '/n')
, etc
Any help would be appreciated!
I've thus far only been able to split text from the text file into a list but would like to take every two items from that list and write to text file using the format: ('list_item1/3/5etc' + ' ' + 'list_item2/4/6etc' + '/n')
with open(r'filename', 'w') as fp:
fp.write(" ".join(str(item) for item in words))