python返回汉字的首字母
def get_first_letter(char):
char=char.encode('GBK')
if char<b"xb0xa1" or char>b"xd7xf9":
return ""
if char<b"xb0xc4":
return "a"
if char<b"xb2xc0":
return "b"
if char<b"xb4xed":
return "c"
if char<b"xb6xe9":
return "d"
if char<b"xb7xa1":
return "e"
if char<b"xb8xc0":
return "f"
if char<b"xb9xfd":
return "g"
if char<b"xbbxf6":
return "h"
if char<b"xbfxa5":
return "j"
if char<b"xc0xab":
return "k"
if char<b"xc2xe7":
return "l"
if char<b"xc4xc2":
return "m"
if char<b"xc5xb5":
return "n"
if char<b"xc5xbd":
return "o"
if char<b"xc6xd9":
return "p"
if char<b"xc8xba":
return "q"
if char<b"xc8xf5":
return "r"
if char<b"xcbxf9":
return "s"
if char<b"xcdxd9":
return "t"
if char<b"xcexf3":
return "w"
if char<b"xd1x88":
return "x"
if char<b"xd4xd0":
return "y"
if char<b"xd7xf9":
return "z"
来源:PY学习网:原文地址:https://www.py.cn/article.html