Skip to content

Instantly share code, notes, and snippets.

@lxfly2000
Created February 25, 2020 11:20
Show Gist options
  • Save lxfly2000/3bfe51e3e494732852a2e56eccae1dde to your computer and use it in GitHub Desktop.
Save lxfly2000/3bfe51e3e494732852a2e56eccae1dde to your computer and use it in GitHub Desktop.
用于输出CID码表各字符所属区间的码表分布
#python 3.8.1
#encoding=utf-8
#用于输出CID码表各字符所属区间的码表分布
import sys
table=dict()
def readtable(path):
f=open(path)
while True:
elems=f.readline().split('\t')
if elems[0]=='':
break
num=int(elems[0])
cls=elems[1]
if table.get(cls)==None:
table[cls]=set()
table[cls].add(num)
def sorttable():
for e in table:
table[e]=list(table[e])
table[e].sort()
def outputtable():
for e in table:
print(e,': ',end='',sep='')
a=0
for i in range(0,len(table[e])):
if i+1==len(table[e]) or table[e][i+1]-table[e][i]!=1:
if a>0:
print(', ',end='',sep='')
print(table[e][a],'-',table[e][i],end='',sep='')
a=i+1
print('')
if len(sys.argv)==1:
print('命令行:clsord <ordering文件>')
else:
readtable(sys.argv[1])
sorttable()
outputtable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment