123
This commit is contained in:
parent
16747b0bc8
commit
e02de146b5
30
01.py
Normal file
30
01.py
Normal 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")
|
0
process_string.py
Normal file
0
process_string.py
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
13036
text_original_cnname/ch2.json
Normal file
13036
text_original_cnname/ch2.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user