龙空技术网

python打印出八卦和六十四卦的符号和unicode编码

程序化交易A2Z 1297

前言:

如今朋友们对“unicode编码转换算法”大概比较关怀,我们都需要了解一些“unicode编码转换算法”的相关文章。那么小编在网摘上网罗了一些关于“unicode编码转换算法””的相关文章,希望同学们能喜欢,小伙伴们快快来了解一下吧!

易经中的八卦和六十四卦符号,文档输入时都不是很方便,word或有些拼音输入法都可以把八卦符号当作特殊符号来输入,很少提供六十四卦符号,碰到六十四卦符号就有点麻烦了,甚至不得不绘制成相应的图形来处理,但是六十四卦符号在unicode字符集中都有,只是和八卦符号的编码不相邻。

前两天写代码时,正好也遇到六十四符号输入和输出的问题,就写了一小段python代码,把八卦和六十四卦符号及其unicode编码打印出来,方便查找。

代码段如下:

gua8_hanzi = ["乾","兑","离","震","巽","坎","艮","坤"]gua64_hanzi = ["乾","坤","屯","蒙","需","讼","师","比","小畜","履","泰","否",              "同人","大有","谦","豫","随","蛊","临","观","噬嗑","贲",              "剥","复","无妄","大畜","颐","大过","坎","离",              "咸","恒","遁","大壮","晋","明夷","家人","睽",              "蹇","解","损","益","夬","姤","萃","升","困","井","革","鼎","震",              "艮","渐","归妹","丰","旅","巽","兑","涣","节","中孚",              "小过","既济","未济"]print(len(gua8_hanzi),len(gua64_hanzi))

8, 64

以上语句构建八卦和六十四卦的汉字的列表,并确认个数。

symbol8 = []symbol8_unicode = []for i in range(2630,2638):    expression = "u'\\u"+str(i)+"'"     symbol8.append(eval(expression))    symbol8_unicode.append(str(i))symbol64 = []  symbol64_unicode = []for i in range(19904,19968):    expression = "u'\\u"+str(hex(i))[2:] + "'"     symbol64.append(eval(expression))     symbol64_unicode.append(str(i)) 

下面打印出八卦的汉字名、符号及其unicode编码,

print('八卦:')print("\t".join("".join([gua_zi,' ',gua_sign,' ',gua_unicode]) for gua_sign,gua_zi,gua_unicode in list(zip(gua8_hanzi[:4],symbol8[:4],symbol8_unicode[:4]))))print("\t".join("".join([gua_zi,' ',gua_sign,' ',gua_unicode]) for gua_sign,gua_zi,gua_unicode in list(zip(gua8_hanzi[4:],symbol8[4:],symbol8_unicode[4:]))))

输出结果如下:

八卦:☰ 乾 2630	☱ 兑 2631	☲ 离 2632	☳ 震 2633☴ 巽 2634	☵ 坎 2635	☶ 艮 2636	☷ 坤 2637

下面打印出六十四卦的汉字名、符号及其unicode编码,

print("六十四卦:")for i in range(0,64,8):    print("\t".join(["".join([x,' ',y,' ',z]) for x,y,z in zip(gua64_hanzi[i:i+8],symbol64[i:i+8],symbol64_unicode[i:i*8])]))

输出结果如下:

六十四卦:小畜 ䷈ 19912	履 ䷉ 19913	泰 ䷊ 19914	否 ䷋ 19915	同人 ䷌ 19916	大有 ䷍ 19917	谦 ䷎ 19918	豫 ䷏ 19919随 ䷐ 19920	蛊 ䷑ 19921	临 ䷒ 19922	观 ䷓ 19923	噬嗑 ䷔ 19924	贲 ䷕ 19925	剥 ䷖ 19926	复 ䷗ 19927无妄 ䷘ 19928	大畜 ䷙ 19929	颐 ䷚ 19930	大过 ䷛ 19931	坎 ䷜ 19932	离 ䷝ 19933	咸 ䷞ 19934	恒 ䷟ 19935遁 ䷠ 19936	大壮 ䷡ 19937	晋 ䷢ 19938	明夷 ䷣ 19939	家人 ䷤ 19940	睽 ䷥ 19941	蹇 ䷦ 19942	解 ䷧ 19943损 ䷨ 19944	益 ䷩ 19945	夬 ䷪ 19946	姤 ䷫ 19947	萃 ䷬ 19948	升 ䷭ 19949	困 ䷮ 19950	井 ䷯ 19951革 ䷰ 19952	鼎 ䷱ 19953	震 ䷲ 19954	艮 ䷳ 19955	渐 ䷴ 19956	归妹 ䷵ 19957	丰 ䷶ 19958	旅 ䷷ 19959巽 ䷸ 19960	兑 ䷹ 19961	涣 ䷺ 19962	节 ䷻ 19963	中孚 ䷼ 19964	小过 ䷽ 19965	既济 ䷾ 19966	未济 ䷿ 19967

(本文完)

标签: #unicode编码转换算法