以下是一个Python代码示例,实现上述需求: ```python # 读取码表文件 with open("码表.txt", "r", encoding="utf-8") as file: lines = file.readlines() # 创建编码库 code_library = {} # 遍历每一行 for line in lines: line = line.strip() # 去掉换行符和空白字符 if line: word, code = line.split("\t") # 拆分汉字词语和编码 if code in code_library: code_library[code] += 1 # 编码已存在,次数加1 else: code_library[code] = 1 # 编码不存在,设置初始次数为1 # 将原始行和次数写入新文件 with open("新文件.txt", "a", encoding="utf-8") as new_file: new_file.write(f"{word}\t{code}\t{code_library[code]}\n") ``` 上述代码假设码表文件名为"码表.txt",将处理后的结果写入新文件"新文件.txt"。 [2024-05-31 10:53:14 | AI写代码神器 | 514点数解答]