dictionary_to_rows.py 773 B

12345678910111213141516171819202122232425
  1. def process_file(input_file, output_file):
  2. unique_terms = set()
  3. # Read the input file and collect unique terms
  4. with open(input_file, 'r', encoding='utf-8') as f:
  5. for line in f:
  6. terms = line.strip().split()
  7. unique_terms.update(terms)
  8. # Sort the unique terms alphabetically
  9. sorted_terms = sorted(unique_terms)
  10. # Write the unique terms to the output file
  11. with open(output_file, 'w', encoding='utf-8') as f:
  12. for term in sorted_terms:
  13. f.write(f"{term}\n")
  14. print(f"Processed {len(unique_terms)} unique terms.")
  15. # Process the file
  16. input_file = 'dictionary_reviewed.txt' # Replace with your input file name
  17. output_file = 'dictionary_reviewed_rows.txt'
  18. process_file(input_file, output_file)