日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python汉字转拼音首字母_python获取一组汉字拼音首字母的方法

發(fā)布時(shí)間:2023/12/15 python 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python汉字转拼音首字母_python获取一组汉字拼音首字母的方法 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

作者:不吃皮蛋 字體: 類型:轉(zhuǎn)載

這篇文章主要介紹了python獲取一組漢字拼音首字母的方法,涉及Python針對(duì)漢字操作的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了python獲取一組漢字拼音首字母的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

#!/usr/bin/env python # -*- coding: utf-8 -*- def multi_get_letter(str_input): if isinstance(str_input, unicode): unicode_str = str_input else: try: unicode_str = str_input.decode(‘utf8‘) except: try: unicode_str = str_input.decode(‘gbk‘) except: print ‘unknown coding‘ return return_list = for one_unicode in unicode_str: return_list.append(single_get_first(one_unicode)) return return_list def single_get_first(unicode1): str1 = unicode1.encode(‘gbk‘) try: ord(str1) return str1 except: asc = ord(str1) * 256 + ord(str1) - 65536 if asc >= -20319 and asc <= -20284: return ‘a(chǎn)‘ 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 main(str_input): a = multi_get_letter(str_input) b = ‘‘ for i in a: b= b+i print b if __name__ == "__main__": str_input=u‘歡迎你‘ main(str_input)

希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。

免責(zé)申明:本欄目所發(fā)資料信息部分來自網(wǎng)絡(luò),僅供大家學(xué)習(xí)、交流。我們尊重原創(chuàng)作者和單位,支持正版。若本文侵犯了您的權(quán)益。請(qǐng)點(diǎn)擊這里

總結(jié)

以上是生活随笔為你收集整理的python汉字转拼音首字母_python获取一组汉字拼音首字母的方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。