mirror of
https://github.com/halfrost/LeetCode-Go.git
synced 2025-07-04 16:12:47 +08:00
Add word count
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
|
||||
<p align='center'>
|
||||
<a href="https://github.com/halfrost/LeetCode-Go/releases/" rel="nofollow"><img alt="GitHub All Releases" src="https://img.shields.io/github/downloads/halfrost/LeetCode-Go/total?label=PDF%20downloads"></a>
|
||||
<img src="https://img.shields.io/badge/Total%20Word%20Count-738884-success">
|
||||
<img src="https://github.com/halfrost/LeetCode-Go/workflows/Deploy%20leetcode-cookbook/badge.svg?branch=master">
|
||||
<img src="https://travis-ci.org/halfrost/LeetCode-Go.svg?branch=master">
|
||||
<img src="https://goreportcard.com/badge/github.com/halfrost/LeetCode-Go">
|
||||
|
29
website/content/ChapterFour/pytool/WordCount.py
Normal file
29
website/content/ChapterFour/pytool/WordCount.py
Normal file
@ -0,0 +1,29 @@
|
||||
from collections import defaultdict
|
||||
import glob
|
||||
import os
|
||||
|
||||
|
||||
def str_count2(str):
|
||||
count_zh = count_dg = 0
|
||||
for s in str:
|
||||
# 中文字符范围
|
||||
if '\u4e00' <= s <= '\u9fff':
|
||||
count_zh += 1
|
||||
if s.isdigit():
|
||||
count_dg += 1
|
||||
# print(count_zh + count_dg)
|
||||
return count_zh + count_dg
|
||||
|
||||
current_working_dir = os.getcwd()
|
||||
# print(f"current_working_dir: {current_working_dir}")
|
||||
|
||||
dir_names = glob.glob("*.md")
|
||||
dir_names.sort()
|
||||
|
||||
word_count = 0
|
||||
for file_name in dir_names:
|
||||
with open(file_name, "r") as myfile:
|
||||
codeContent = myfile.read()
|
||||
print("当前读取文件: {}, 字数统计: {}".format(file_name, str_count2(codeContent)))
|
||||
word_count += str_count2(codeContent)
|
||||
print(word_count)
|
Reference in New Issue
Block a user