| import json | |
| def extract_unique_strings(input_file_path, output_file_path): | |
| with open(input_file_path, 'r', encoding='utf-8') as file: | |
| items = json.load(file) | |
| # 提取item[1],这里假设每个item都至少有两个元素 | |
| strings = [item[1] for item in items if len(item) > 1] | |
| # 去重 | |
| unique_strings = list(set(strings)) | |
| # 保存为JSON文件 | |
| with open(output_file_path, 'w', encoding='utf-8') as file: | |
| json.dump(unique_strings, file, ensure_ascii=False, indent=4) | |
| # 打印去重后的列表长度 | |
| print(f"Number of unique strings: {len(unique_strings)}") | |
| # 替换以下路径为你的输入文件和输出文件路径 | |
| input_file_path = 'train/sft/medicalExam_es_dup.json' | |
| output_file_path = 'train/sft/medicalExam_es_dup_question.json' | |
| extract_unique_strings(input_file_path, output_file_path) | |