I have written a piece of code in Python to copy an existing text file (.txt) to a new file in the same location (with a different name). This copies all of the text from the original text file, as expected:
a=open("file1.txt", "r") #existing file
b=open("file2.txt", "w") #file did not previously exist, hence "w"
for reform1 in a.readlines():
b.write(reform1) #write the lines from 'reform1'
reform1=a.readlines() #read the lines in the file
a.close() #close file a (file1)
b.close() #close file b (file2)
I have now been asked to amend the new file, to remove both duplicate lines and blank lines from the file that were copied over (whilst preserving the original) and leaving the rest of the text (unique lines) as it is. How to do this?