最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python 獲取中文字拼音首個字母的方法

 更新時間:2018年11月28日 08:30:51   作者:HuangZhang_123  
今天小編就為大家分享一篇Python 獲取中文字拼音首個字母的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

Python:3.5

代碼如下:

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('你好'))

運行結(jié)果:

Python 中文字拼音首個字母

以上這篇Python 獲取中文字拼音首個字母的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

  • Python中無限循環(huán)需要什么條件

    Python中無限循環(huán)需要什么條件

    在本篇文章里小編給大家分享的是關于Python中無限循環(huán)的條件的相關文章,需要的朋友們可以參考下。
    2020-05-05
  • python 操作excel表格的方法

    python 操作excel表格的方法

    這篇文章主要介紹了python 操作excel表格的方法,幫助大家更好的理解和使用python,感興趣的朋友可以了解下
    2020-12-12
  • 一文帶你了解Python中的注釋及變量

    一文帶你了解Python中的注釋及變量

    這篇文章主要給大家介紹了關于Python中注釋及變量的相關資料,Python是一門動態(tài)類型的語言,因此無須提前聲明變量類型,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-07-07
  • Python Numpy中數(shù)組的集合操作詳解

    Python Numpy中數(shù)組的集合操作詳解

    這篇文章主要為大家詳細介紹了Python Numpy中數(shù)組的一些集合操作方法,文中的示例代碼講解詳細,對我們學習Python有一定幫助,需要的可以參考一下
    2022-08-08
  • Python3使用正則表達式爬取內(nèi)涵段子示例

    Python3使用正則表達式爬取內(nèi)涵段子示例

    這篇文章主要介紹了Python3使用正則表達式爬取內(nèi)涵段子,涉及Python正則匹配與文件讀寫相關操作技巧,需要的朋友可以參考下
    2018-04-04
  • python爬蟲爬取指定內(nèi)容的解決方法

    python爬蟲爬取指定內(nèi)容的解決方法

    這篇文章主要介紹了python爬蟲爬取指定內(nèi)容,爬取一些網(wǎng)站下指定的內(nèi)容,一般來說可以用xpath來直接從網(wǎng)頁上來獲取,但是當我們獲取的內(nèi)容不唯一的時候我們無法選擇,我們所需要的、所指定的內(nèi)容,需要的朋友可以參考下
    2022-06-06
  • Python 實現(xiàn)訓練集、測試集隨機劃分

    Python 實現(xiàn)訓練集、測試集隨機劃分

    今天小編就為大家分享一篇Python 實現(xiàn)訓練集、測試集隨機劃分,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • Python GUI編程完整示例

    Python GUI編程完整示例

    這篇文章主要介紹了Python GUI編程,結(jié)合完整示例形式分析了Python基于tkinter模塊的GUI圖形界面編程相關實現(xiàn)技巧,需要的朋友可以參考下
    2019-04-04
  • python里使用正則的findall函數(shù)的實例詳解

    python里使用正則的findall函數(shù)的實例詳解

    這篇文章主要介紹了python里使用正則的findall函數(shù)的實例詳解的相關資料,希望通過本文能幫助到大家,需要的朋友可以參考下
    2017-10-10
  • python中的json總結(jié)

    python中的json總結(jié)

    JSON(JavaScript Object Notation, JS 對象簡譜) 是一種輕量級的數(shù)據(jù)交換格式。本文重點給大家介紹python中的json,感興趣的朋友跟隨小編一起看看吧
    2018-10-10

最新評論

客服| 彩票| 峡江县| 双牌县| 锦屏县| 平潭县| 睢宁县| 大新县| 哈密市| 濉溪县| 宁化县| 麻阳| 六枝特区| 平湖市| 重庆市| 营山县| 叙永县| 龙川县| 邵东县| 应城市| 确山县| 荆门市| 乌苏市| 延川县| 平山县| 板桥市| 隆德县| 广州市| 济阳县| 宝清县| 金平| 合川市| 浦城县| 青浦区| 肃北| 大安市| 西吉县| 宣化县| 佛山市| 古蔺县| 德阳市|