密码统计分析

#函数
def do_something_with(l, dou):
    #统计单字母,双字母个数记录于字典a中
    l = filter(str.isalpha, l.lower())
    #对字符串l,只提取字母,且规定为小写
    for i in l:
        
        #遍历单字母
        if(i in a):
            a[i] = a[i] + 1
        else:
            a[i] = 1
        
        #遍历双字母
        dou = dou[1] + i
        if(dou[0] != ' '):
            if(dou in a):
                a[dou] = a[dou] + 1
            else:
                a[dou] = 1
a = {};
dou = '  '
file_object = open('statistics.txt', 'r')
try:
    for line in file_object:
        do_something_with(line, dou)
finally:
    file_object.close()
print(a)
len(a)
import pandas as pd
df = pd.DataFrame(list(a.items()))
df.sort_index(axis = 0,ascending = False,by = 1)

#output
  	0 	1
12 	e 	118461
26 	t 	79827
1 	a 	74240
24 	o 	71682
45 	i 	66301
6 	n 	64598
30 	s 	59412
3 	r 	56109
34 	h 	55006
8 	d 	44194


... 	... 	...


603 	éo 	1
639 	èt 	1
610 	ès 	1
625 	jy 	1
337 	xv 	1
6301
631 	êm 	1
336 	sx 	1
6381
662 	cj 	1
663 rows × 2 columns
import matplotlib.pyplot as plt
df.plot(kind='barh', figsize=(10, 6)) 
df.plot(kind='line') 
plt.xlabel('number') 
# add to x-label to the plot 
plt.ylabel('alpher') 
# add y-label to the plot 
plt.title("statistics") 
# add title to the plot 
plt.show()			

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值