# Read the file with open("input-with-duplicates.txt", "r", encoding="utf-8") as file: lines = file.readlines() # Remove duplicates by converting to a set, then back to list to keep the order unique_lines = set(lines) # Write the unique lines back to the file or a new file with open("output-without-duplicates.txt", "w", encoding="utf-8") as file: file.writelines(unique_lines)