-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathutils.py
39 lines (34 loc) · 902 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# -*- coding: UTF-8 -*-
import matplotlib.pyplot as plt
def strQ2B(ustring):
'''全角转半角'''
rstring = ''
for uchar in ustring:
inside_code = ord(uchar)
if inside_code == 12288: # 全角空格直接转换
inside_code = 32
elif (inside_code >= 65281 and inside_code <= 65374): # 全角字符(除空格)根据关系转化
inside_code -= 65248
rstring += chr(inside_code)
return rstring
def plot_lengths(lengths):
lengths = sorted(lengths)
pre_i = lengths[0]
count = []
x = []
j = 0
for i in lengths:
if pre_i == i:
j += 1
else:
count.append(j)
x.append(pre_i)
j = 0
pre_i = i
# print(len(list(filter(lambda l: l > 300, lengths))))
print('count size: ' + str(len(lengths)))
print('max length: ' + str(lengths[-1]))
x = range(len(count))
plt.plot(x, count)
plt.ylabel('长度')
plt.show()