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('你好'))
執行結果:
相關文章
- php獲取漢字的拼音 拼音首字母PHP
- 用Oracle的NLSSORT獲取拼音首字母Oracle
- [轉]SQL獲取漢字拼音首字母函式SQL函式
- 在Excel中如何獲取漢字拼音首字母?Excel
- 在vc中實現獲取漢字拼音的首字母
- 直播原始碼開發,vue漢字獲取字母首拼或拼音、大小寫原始碼Vue
- 摘抄Excel和FoxPro獲取漢字拼音首字母縮寫的方法.Excel
- 如何獲取漢字拼音首字母?一般用於通訊錄
- 取漢字的拼音首字母的SQL函式SQL函式
- 獲取漢字串的拼音助記碼字串
- 返回字串的拼音首字母 (轉)字串
- mysql獲取漢字的首字母MySql
- C# 獲取漢字首字母C#
- java獲取漢字的首字母Java
- jquery獲取元素中文字的長度jQuery
- 城市列表-根據拼音首字母排序排序
- vue中文字框自動獲取焦點Vue
- js獲取選中文字程式碼例項JS
- C#中取得漢語拼音首字母C#
- Sql Server資料庫漢字按字母、筆劃、拼音首字母、排序SQLServer資料庫排序
- 如何讓漢字以拼音字母順序排序排序
- js獲取選中文字值的例項程式碼JS
- Python如何列印出26個大寫字母和26個小寫字母Python
- XamarinEssentials教程獲取首選項的值
- ORACLE SQL函式中文漢字轉拼音首字母OracleSQL函式
- js實現的獲取選中文字程式碼例項JS
- js獲取數字和字母隨機數程式碼例項JS隨機
- 匹配字母、數字和中文字元正規表示式字元
- oralce中漢字轉為拼音首字母的函式(轉)函式
- Java使用Collections對中文字元進行首字母排序Java字元排序
- python如何只獲取日期Python
- python使用requests獲取cookiePythonCookie
- DB2中建立漢字拼音首字母的SQL函式DB2SQL函式
- Python - opencv-python 獲取影片尺寸PythonOpenCV
- C# 漢字轉拼音 使用微軟的Visual Studio International Pack 類庫提取漢字拼音首字母C#微軟
- python如何獲取本機ipPython
- python中獲取如何Series值Python
- 【Python】獲取機器使用資訊Python