This commit is contained in:
2025-05-14 10:51:15 +08:00
parent 16747b0bc8
commit e02de146b5
7 changed files with 35250 additions and 22249 deletions

30
01.py Normal file
View File

@ -0,0 +1,30 @@
import json
import re
def parse_key(key):
parts = key.split("_")
parsed = []
for part in parts:
if part.isdigit():
parsed.append((0, int(part))) # 数字优先,按大小
else:
parsed.append((1, part)) # 字符串按字典序
return parsed
def sort_json_keys(input_file, output_file):
with open(input_file, "r", encoding="utf-8") as f:
data = json.load(f)
sorted_items = sorted(data.items(), key=lambda item: parse_key(item[0]))
sorted_data = {k: v for k, v in sorted_items}
with open(output_file, "w", encoding="utf-8") as f:
json.dump(sorted_data, f, ensure_ascii=False, indent=2)
# 示例用法
if __name__ == "__main__":
sort_json_keys("text_original/ch1/zh_CN.json", "text_original/ch1/zh_CN.json")