Update 一锅烩.py
This commit is contained in:
@@ -221,7 +221,7 @@ replacements = {
|
|||||||
with open('汇总.txt', 'r', encoding='utf-8') as file:
|
with open('汇总.txt', 'r', encoding='utf-8') as file:
|
||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
# 创建新文件并写入替换后的内容
|
# 创建新文件并写入替换后的内容
|
||||||
with open('汇总.txt', 'w', encoding='utf-8') as new_file:
|
with open('2.txt', 'w', encoding='utf-8') as new_file:
|
||||||
for line in lines:
|
for line in lines:
|
||||||
for old, new in replacements.items():
|
for old, new in replacements.items():
|
||||||
line = line.replace(old, new)
|
line = line.replace(old, new)
|
||||||
@@ -230,25 +230,6 @@ print("替换完成,新文件已保存。")
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import re
|
|
||||||
from pypinyin import lazy_pinyin
|
|
||||||
# 打开一个utf-8编码的文本文件
|
|
||||||
with open("汇总.txt", "r", encoding="utf-8") as file:
|
|
||||||
# 读取所有行并存储到列表中
|
|
||||||
lines = file.readlines()
|
|
||||||
# 定义一个函数,用于提取每行的第一个数字
|
|
||||||
def extract_first_number(line):
|
|
||||||
match = re.search(r'\d+', line)
|
|
||||||
return int(match.group()) if match else float('inf')
|
|
||||||
# 对列表中的行进行排序,按照第一个数字的大小排列,其余行按中文排序
|
|
||||||
sorted_lines = sorted(lines, key=lambda x: (not 'CCTV' in x, extract_first_number(x) if 'CCTV' in x else lazy_pinyin(x.strip())))
|
|
||||||
# 将排序后的行写入新的utf-8编码的文本文件
|
|
||||||
with open("2.txt", "w", encoding="utf-8") as file:
|
|
||||||
for line in sorted_lines:
|
|
||||||
file.write(line)
|
|
||||||
|
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
def filter_lines(file_path):
|
def filter_lines(file_path):
|
||||||
@@ -362,6 +343,22 @@ with open('2.txt', 'w', encoding='utf-8') as new_file:
|
|||||||
new_file.write(line) # 写入新文件
|
new_file.write(line) # 写入新文件
|
||||||
print("新文件已保存。") # 打印完成信息
|
print("新文件已保存。") # 打印完成信息
|
||||||
|
|
||||||
|
import re
|
||||||
|
from pypinyin import lazy_pinyin
|
||||||
|
# 打开一个utf-8编码的文本文件
|
||||||
|
with open("2.txt", "r", encoding="utf-8") as file:
|
||||||
|
# 读取所有行并存储到列表中
|
||||||
|
lines = file.readlines()
|
||||||
|
# 定义一个函数,用于提取每行的第一个数字
|
||||||
|
def extract_first_number(line):
|
||||||
|
match = re.search(r'\d+', line)
|
||||||
|
return int(match.group()) if match else float('inf')
|
||||||
|
# 对列表中的行进行排序,按照第一个数字的大小排列,其余行按中文排序
|
||||||
|
sorted_lines = sorted(lines, key=lambda x: (not 'CCTV' in x, extract_first_number(x) if 'CCTV' in x else lazy_pinyin(x.strip())))
|
||||||
|
# 将排序后的行写入新的utf-8编码的文本文件
|
||||||
|
with open("2.txt", "w", encoding="utf-8") as file:
|
||||||
|
for line in sorted_lines:
|
||||||
|
file.write(line)
|
||||||
|
|
||||||
|
|
||||||
########################################################################################################################################################################################
|
########################################################################################################################################################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user