敲击最多的键------验证

简介:

--------看了这篇文章,觉得很有意思,后面博友评论的也很多。其实我也一直在纳闷为什么e,r,s,t,i键敲击的最多。后来就用想应该写个程序验证一下,拿起了小半年没有用过的python,费了一个小时,终于搞定。


import os

alist = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,\
         0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]



#
#list all file in the directory and sub directory
#input:directory path
#outpur:none
#
def lstallfl(directory):
    dirs = os.listdir(directory)
    
    for item in dirs:
        if not item.startswith('.'):
        
            if os.path.isdir(directory+item+"/"):    
                #print   directory+item+"/"
                lstallfl(directory+item+"/")
                
            elif os.path.isfile(directory+item):    
                calculate(directory+item)
#end of function 

#
#calculate every file
#input:none
#output:none
#
def calculate(filepath):
    #test the filepath
    if not os.path.isfile(filepath):
        return
    if not filepath.endswith('c') or filepath.endswith('h'):
        return 
    else:
        #print filepath
        f = open(filepath, 'r')
        alllines = f.readlines()
        f.close()
        
        for eachline in alllines:
            statistics(eachline)
#end of function 

            
#
#statistics the number
#input:none
#output:none 
#
def statistics(aString):
    for char in aString: 
        alist[255] += 1
        alist[ord(char)] += 1
#end of function 
        
#
#process the result
#input:none
#output:none
#
def finalprocess():
    for i in range(56,91):
        alist[i+32] += alist[i]
        alist[i] = 0
    
    for i in range(32,65):
        print i,chr(i),alist[i]
        
    for i in range(91,127):
        print i,chr(i),alist[i]
#end of function 

#main function
if __name__ == '__main__':
    lstallfl("/home/archy/SourceCode/")
    finalprocess();

上面是写的代码,我们看一下运行结果:


32   457011
33 ! 1638
34 " 8792
35 # 3257
36 $ 365
37 % 959
38 & 8485
39 ' 6422
40 ( 25822
41 ) 25959
42 * 104040
43 + 7871
44 , 13738
45 - 17813
46 . 8032
47 / 13931
48 0 18880
49 1 9675
50 2 5041
51 3 1996
52 4 1443
53 5 1689
54 6 1625
55 7 1689
56 8 0
57 9 0
58 : 0
59 ; 0
60 < 0
61 = 0
62 > 0
63 ? 0
64 @ 0
91 [ 41808
92 \ 5029
93 ] 29069
94 ^ 8194
95 _ 29110
96 ` 29
97 a 52294
98 b 18025
99 c 39949
100 d 29065
101 e 91546
102 f 30223
103 g 19702
104 h 18122
105 i 65054
106 j 1818
107 k 9225
108 l 36025
109 m 21704
110 n 54152
111 o 56740
112 p 43104
113 q 2325
114 r 62993
115 s 61789
116 t 87561
117 u 30620
118 v 9783
119 w 7661
120 x 6540
121 y 9855
122 z 6270
123 { 6667
124 | 2099
125 } 6674
126 ~ 259

这里统计了ucos操作系统代码和unix操作系统代码,代码量一般,但是我觉得这两个系统的代码写的比较标准比较有代表性。从运行的结果看出,e,r,s,t,i,*,空格键用的比较多,其实我也不知道那位作者是如何统计的,我也只是统计了两个操作系统的代码,可能有偏差,但是我相信偏差不会太大。

 

有兴趣的博友可以测试一下c#、汇编等语言的键敲击率,也欢迎提出宝贵意见。 


相关文章
|
7月前
|
算法
26.【算法五章-----02】
26.【算法五章-----02】
38 0
|
5月前
|
存储 索引
集合专题----set篇
集合专题----set篇
|
7月前
|
算法
29.【算法五章-----03(未完毕)】
29.【算法五章-----03(未完毕)】
23 0
29.【算法五章-----03(未完毕)】
|
7月前
|
算法 C++
22.【算法五章-----01】
22.【算法五章-----01】
23 0
|
8月前
|
小程序 前端开发 程序员
小程序----网络数据请求
小程序----网络数据请求
Win系统 - 你知道 insert 键的隐藏功能吗?
Win系统 - 你知道 insert 键的隐藏功能吗?
611 0
Win系统 - 你知道 insert 键的隐藏功能吗?
|
数据安全/隐私保护
C#--用户密码处理------混淆密码加密
近期刚好做新框架的用户数据安全这块 密码的保护措施:混淆加密--------------------------------拙见----------贴上代码--请指教 1:生成混淆数据,---存入数据表字段 2:获取密码混淆加密字符串-----存入数据表字段      /*-------...
1320 0