针对pulse-transit的工具
This commit is contained in:
26
txt_counter.py
Normal file
26
txt_counter.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from collections import Counter
|
||||
|
||||
def count_lines(file_path):
|
||||
# 读取文件并统计每一行的出现次数
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
lines = file.readlines()
|
||||
|
||||
# 使用Counter统计每一行的出现次数
|
||||
line_counts = Counter(lines)
|
||||
|
||||
# 按出现次数从高到低排序
|
||||
sorted_line_counts = line_counts.most_common()
|
||||
|
||||
return sorted_line_counts
|
||||
|
||||
def main(file_path):
|
||||
sorted_line_counts = count_lines(file_path)
|
||||
|
||||
# 打印结果
|
||||
for line, count in sorted_line_counts:
|
||||
print(f'{line.strip()} - Count: {count}')
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 指定你的txt文件路径
|
||||
file_path = "D://python_study//big_boss//doc//output//all_processed.txt"
|
||||
main(file_path)
|
||||
Reference in New Issue
Block a user