Skip to content

Commit e2a31f2

Browse files
committed
Add word count
1 parent fb9da5f commit e2a31f2

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<p align='center'>
1111
<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>
12+
<img src="https://img.shields.io/badge/Total%20Word%20Count-738884-success">
1213
<img src="https://github.com/halfrost/LeetCode-Go/workflows/Deploy%20leetcode-cookbook/badge.svg?branch=master">
1314
<img src="https://travis-ci.org/halfrost/LeetCode-Go.svg?branch=master">
1415
<img src="https://goreportcard.com/badge/github.com/halfrost/LeetCode-Go">
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from collections import defaultdict
2+
import glob
3+
import os
4+
5+
6+
def str_count2(str):
7+
count_zh = count_dg = 0
8+
for s in str:
9+
# 中文字符范围
10+
if '\u4e00' <= s <= '\u9fff':
11+
count_zh += 1
12+
if s.isdigit():
13+
count_dg += 1
14+
# print(count_zh + count_dg)
15+
return count_zh + count_dg
16+
17+
current_working_dir = os.getcwd()
18+
# print(f"current_working_dir: {current_working_dir}")
19+
20+
dir_names = glob.glob("*.md")
21+
dir_names.sort()
22+
23+
word_count = 0
24+
for file_name in dir_names:
25+
with open(file_name, "r") as myfile:
26+
codeContent = myfile.read()
27+
print("当前读取文件: {}, 字数统计: {}".format(file_name, str_count2(codeContent)))
28+
word_count += str_count2(codeContent)
29+
print(word_count)

0 commit comments

Comments
 (0)