Add word count

This commit is contained in:
YDZ
2020-09-20 16:04:49 +08:00
parent fb9da5f885
commit e2a31f2a92
2 changed files with 30 additions and 0 deletions

View File

@ -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">

View 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)