Python 獲取中文字拼音首個字母
Python:3.5
歡迎加入學習交流QQ群:657341423
程式碼如下:
def single_get_first(unicode1):
str1 = unicode1.encode('gbk')
try:
ord(str1)
return str1.decode('gbk')
except:
asc = str1[0] * 256 + str1[1] - 65536
if asc >= -20319 and asc <= -20284:
return 'a'
if asc >= -20283 and asc <= -19776:
return 'b'
if asc >= -19775 and asc <= -19219:
return 'c'
if asc >= -19218 and asc <= -18711:
return 'd'
if asc >= -18710 and asc <= -18527:
return 'e'
if asc >= -18526 and asc <= -18240:
return 'f'
if asc >= -18239 and asc <= -17923:
return 'g'
if asc >= -17922 and asc <= -17418:
return 'h'
if asc >= -17417 and asc <= -16475:
return 'j'
if asc >= -16474 and asc <= -16213:
return 'k'
if asc >= -16212 and asc <= -15641:
return 'l'
if asc >= -15640 and asc <= -15166:
return 'm'
if asc >= -15165 and asc <= -14923:
return 'n'
if asc >= -14922 and asc <= -14915:
return 'o'
if asc >= -14914 and asc <= -14631:
return 'p'
if asc >= -14630 and asc <= -14150:
return 'q'
if asc >= -14149 and asc <= -14091:
return 'r'
if asc >= -14090 and asc <= -13119:
return 's'
if asc >= -13118 and asc <= -12839:
return 't'
if asc >= -12838 and asc <= -12557:
return 'w'
if asc >= -12556 and asc <= -11848:
return 'x'
if asc >= -11847 and asc <= -11056:
return 'y'
if asc >= -11055 and asc <= -10247:
return 'z'
return ''
def getPinyin(string):
if string == None:
return None
lst = list(string)
charLst = []
for l in lst:
charLst.append(single_get_first(l))
return ''.join(charLst)
if __name__ == '__main__':
print(getPinyin('你好'))
執行結果:
相關文章
- 在Excel中如何獲取漢字拼音首字母?Excel
- 直播原始碼開發,vue漢字獲取字母首拼或拼音、大小寫原始碼Vue
- vue中文字框自動獲取焦點Vue
- Python如何列印出26個大寫字母和26個小寫字母Python
- ORACLE SQL函式中文漢字轉拼音首字母OracleSQL函式
- python字典獲取_查Python
- Python獲取星期幾Python
- 匹配字母、數字和中文字元正規表示式字元
- XamarinEssentials教程獲取首選項的值
- python實現獲取成員所在的多個位置Python
- Java使用Collections對中文字元進行首字母排序Java字元排序
- Python - opencv-python 獲取影片尺寸PythonOpenCV
- Python獲取jsonp資料PythonJSON
- python如何只獲取日期Python
- 獲取上個月
- Python 列印中文字元Python字元
- Python如何獲取request response bodyPython
- python中獲取如何Series值Python
- python如何獲取本機ipPython
- python27拼音帶音調Python
- Python基於opencv呼叫攝像頭獲取個人圖片PythonOpenCV
- 字母排列(python實現)Python
- 【Python】獲取機器使用資訊Python
- python 一鍵獲取郵件附件Python
- python 獲取時間的datetime庫Python
- python tkinter如何獲取label內容?Python
- python爬蟲如何獲取表情包Python爬蟲
- python 如何獲取當前時間Python
- 如何使用Python獲取、寫入localStoragePython
- Python 漢字轉拼音的庫--- PyPinyinPython
- 讀取檔案,每行不超過100個字元,輸出每行中字母最多的單詞的字母數字元
- 使用Python獲取ECS相關資訊Python
- python request 獲取cookies value值的方法PythonCookie
- 【Python小隨筆】 SSH 獲取資訊Python
- python獲取zabbix監控項圖形Python
- python的queue佇列獲取資料Python佇列
- python執行shell並獲取結果Python
- python 獲取設定環境變數Python變數
- 如何用python分析xml獲取資料?PythonXML