forked from googlefonts/lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text2uni_range.py
46 lines (37 loc) · 980 Bytes
/
text2uni_range.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
40
41
42
43
44
45
46
import re
strlist = "1231"
ss = [x[0] or x[1] for x in re.findall(r"\{([^}]+)\}|(\S+)", strlist)]
print(ss)
# 去除空格
strlist = strlist.replace(' ', '')
# str 中的每个元素都是一个字符,将其转换为一个整数
cache_list = [ord(c) for c in strlist]
# 压缩
cache_list = list(set(cache_list))
# 排序
cache_list.sort()
remove_list = [123, 125, 9676]
for i in remove_list:
if i in cache_list:
cache_list.remove(i)
result = []
start = cache_list[0]
end = cache_list[0]
for i in range(1, len(cache_list)):
if cache_list[i] - cache_list[i - 1] == 1:
end = cache_list[i]
else:
if start == end:
result.append([start])
else:
result.append([start, end])
start = cache_list[i]
end = cache_list[i]
if start == end:
result.append([start])
else:
result.append([start, end])
print(result)
# 存为txt文件
with open('uni_range.txt', 'w') as f:
f.write(str(result))