import os
import json
from collections import Counter# 按字符计数
label_dir="/Users/thy/Downloads/chinese20240613"
zi_ls=[]withopen(os.path.join(label_dir,"Label.txt"))as f:lines=f.readlines()for line in lines:line = line.strip("\r\n")# print("line:",line)line1=line.split("\t")# print("line1:", line1[1])json_str = json.loads(line1[1])# 提取所有转录文本transcriptions =[item["transcription"]for item in json_str]print(transcriptions)transcriptions1=[]for trans in transcriptions:iflen(trans)==1:transcriptions1.append(trans)else:trans=[char for char in trans]for tran in trans:transcriptions1.append(tran)# print(transcriptions1)for zi in transcriptions1:zi_ls.append(zi)# print("出现的字符串:",set(zi_ls))
char_counts = Counter(zi_ls)# 打印结果for char, count in char_counts.items():print(f"字符 '{char}' 出现了 {count} 次")# 如果需要将结果存储到字典,可以直接使用char_counts# 输出字典内容print(char_counts)
字符出现的次数
import os
import json
from collections import Counter# 按字符计数
label_dir="/Users/thy/Downloads/chinese20240613"
zi_ls=[]withopen(os.path.join(label_dir,"Label.txt"))as f:lines=f.readlines()for line in lines:line = line.strip("\r\n")# print("line:",line)line1=line.split("\t")# print("line1:", line1[1])json_str = json.loads(line1[1])# 提取所有转录文本transcriptions =[item["transcription"]for item in json_str]# print(transcriptions)transcriptions1=[]for trans in transcriptions:transcriptions1.append(trans)print(transcriptions1)for zi in transcriptions1:zi_ls.append(zi)print("出现的字符串:",set(zi_ls))
char_counts = Counter(zi_ls)# 打印结果for char, count in char_counts.items():print(f"字符 '{char}' 出现了 {count} 次")# 如果需要将结果存储到字典,可以直接使用char_counts# 输出字典内容print(char_counts)
文章目录 先挑最值,再把剩下的挑最值,再把剩下的挑最值。。。 -- 排序函数
function selectionSort(arr) -- 外层循环,从数组的第一个元素开始,对每个元素进行排序 for i 1, #arr do -- 假设当前位置的元素是最小的 local …
【SQL Server点滴积累】Setup SQL Server 2008 Database Mirror (一)-CSDN博客今天分享SQL Server 2008 R2搭建数据库镜像(Database Mirror)https://blog.csdn.net/ncutyb123/article/details/139749117?spm1001.2014.3001.5501本篇Blog基于以上Blog步骤进行SQL Server 2008 R…