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

Python 獲取中文字拼音首個(gè)字母的方法

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

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

運(yùn)行結(jié)果:

Python 中文字拼音首個(gè)字母

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

相關(guān)文章

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

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

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

    python 操作excel表格的方法

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

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

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

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

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

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

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

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

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

    Python 實(shí)現(xiàn)訓(xùn)練集、測(cè)試集隨機(jī)劃分

    今天小編就為大家分享一篇Python 實(shí)現(xiàn)訓(xùn)練集、測(cè)試集隨機(jī)劃分,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-01-01
  • Python GUI編程完整示例

    Python GUI編程完整示例

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

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

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

    python中的json總結(jié)

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

最新評(píng)論

邢台县| 徐闻县| 三明市| 阳新县| 灌阳县| 留坝县| 靖西县| 沂南县| 东方市| 大竹县| 北宁市| 宝丰县| 舒城县| 丰原市| 广安市| 河津市| 凌云县| 巍山| 松阳县| 淳安县| 北川| 连平县| 江安县| 江津市| 临江市| 蓬溪县| 武强县| 湘乡市| 德州市| 隆回县| 普安县| 陇西县| 兴安盟| 临西县| 城市| 忻州市| 嘉义县| 襄汾县| 哈巴河县| 宁津县| 嘉善县|