0% found this document useful (0 votes)
12 views1 page

Script

The document contains a Python function that reads a file, removes duplicate lines, sorts them, and writes the unique sorted lines back to the same file. The function is called twice for two different text files. It ensures that the output files contain only unique and sorted lines from the original content.

Uploaded by

Iron Man
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views1 page

Script

The document contains a Python function that reads a file, removes duplicate lines, sorts them, and writes the unique sorted lines back to the same file. The function is called twice for two different text files. It ensures that the output files contain only unique and sorted lines from the original content.

Uploaded by

Iron Man
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

def clean_and_sort_file(file_path):

with open(file_path, 'r') as file:


lines = file.readlines()
unique_sorted_lines = sorted(set(line.strip() for line in lines))
with open(file_path, 'w') as file:
for line in unique_sorted_lines:
file.write(line + '\n')

clean_and_sort_file("Text 1 .txt")
clean_and_sort_file("Text 2 .txt")

You might also like