wordCount 文本计算工具
突发奇想,做的一个文件中的计数工具。
'''
2022/1/18
实现计算文件里(纯文本文件)的字母个数
'''
def word_count(path):
    import numpy as np
    f = open(path, "r")
    a = f.read()
    word = list(np.arange(65, 91, 1))
    bigcount = np.zeros(26)
    smallcount = np.zeros(26)
    allcount = np.zeros(26)
    for i in a:
        for j in word:
            if ord(i) == j:
                bigcount[word.index(j)] = bigcount[word.index(j)] + 1
            if ord(i) == j + 32:
                smallcount[word.index(j)] = smallcount[word.index(j)] + 1
    allcount = bigcount + smallcount
    print("字母   数量    字母   数量")
    print("---------------------------------------------")
    for i in word:
        print(chr(i), ":", " ", str(bigcount[word.index(i)]), " | ", chr(i + 32), ":", " ",
              str(smallcount[word.index(i)]),
              " | ", "总共:", allcount[word.index(i)])
        print("---------------------------------------------")
word_count("D:\\WORKcode\\1.txt")
测试文件
hello world 
my friend.
测试结果
字母   数量   字母   数量
---------------------------------------------
A :   0.0  |  a :   0.0  |  总共:0.0
---------------------------------------------
B :   0.0  |  b :   0.0  |  总共:0.0
---------------------------------------------
C :   0.0  |  c :   0.0  |  总共:0.0
---------------------------------------------
D :   0.0  |  d :   2.0  |  总共:2.0
---------------------------------------------
E :   0.0  |  e :   2.0  |  总共:2.0
---------------------------------------------
F :   0.0  |  f :   1.0  |  总共:1.0
---------------------------------------------
G :   0.0  |  g :   0.0  |  总共:0.0
---------------------------------------------
H :   0.0  |  h :   1.0  |  总共:1.0
---------------------------------------------
I :   0.0  |  i :   1.0  |  总共:1.0
---------------------------------------------
J :   0.0  |  j :   0.0  |  总共:0.0
---------------------------------------------
K :   0.0  |  k :   0.0  |  总共:0.0
---------------------------------------------
L :   0.0  |  l :   3.0  |  总共:3.0
---------------------------------------------
M :   0.0  |  m :   1.0  |  总共:1.0
---------------------------------------------
N :   0.0  |  n :   1.0  |  总共:1.0
---------------------------------------------
O :   0.0  |  o :   2.0  |  总共:2.0
---------------------------------------------
P :   0.0  |  p :   0.0  |  总共:0.0
---------------------------------------------
Q :   0.0  |  q :   0.0  |  总共:0.0
---------------------------------------------
R :   0.0  |  r :   2.0  |  总共:2.0
---------------------------------------------
S :   0.0  |  s :   0.0  |  总共:0.0
---------------------------------------------
T :   0.0  |  t :   0.0  |  总共:0.0
---------------------------------------------
U :   0.0  |  u :   0.0  |  总共:0.0
---------------------------------------------
V :   0.0  |  v :   0.0  |  总共:0.0
---------------------------------------------
W :   0.0  |  w :   1.0  |  总共:1.0
---------------------------------------------
X :   0.0  |  x :   0.0  |  总共:0.0
---------------------------------------------
Y :   0.0  |  y :   1.0  |  总共:1.0
---------------------------------------------
Z :   0.0  |  z :   0.0  |  总共:0.0
---------------------------------------------
后续有可能还会完善,添加更多的功能
持续更新·····
<div style="position: relative; width: 100%; height: 0; padding-bottom: 75%;"><iframe 
src="//player.bilibili.com/player.html?aid=39807850&cid=69927212&page=1" scrolling="no" border="0" 
frameborder="no" framespacing="0" allowfullscreen="true" style="position: absolute; width: 100%; 
height: 100%; left: 0; top: 0;"> </iframe></div>
<div class="dplayer-video-container">
{% dplayer "url=https://www.bilibili.com/video/BV1Et411s7MW?t=1.9" %}
<div>