python 加注拼音-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('你好'))
运行结果:
以上这篇Python 获取中文字拼音首个字母的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
python 加注拼音-Python 获取中文字拼音首个字母的方法相关推荐
- python怎么识别拼音-Python 获取中文字拼音首个字母的方法
Python:3.5 代码如下: def single_get_first(unicode1): str1 = unicode1.encode('gbk') try: ord(str1) return ...
- python拼音怎么写-Python 获取中文字拼音首个字母的方法
Python:3.5 代码如下: def single_get_first(unicode1): str1 = unicode1.encode('gbk') try: ord(str1) return ...
- Python 获取中文字拼音首个字母
Python:3.5 欢迎加入学习交流QQ群:657341423 代码如下: def single_get_first(unicode1):str1 = unicode1.encode('gbk')t ...
- Word文档粘贴的表格中文字有淡灰色背景的去除方法
直接从excel粘贴过来的表格 特征: 无论怎么改字符的底色还是边框底纹都无法去除: 更改字符底纹,该底纹也没有变化: 更改各种格式样式都无法消除: 各种格式刷都不管用. 光标移到别处不会显示灰色背景 ...
- mysql得到中文的拼音_在MySQL中获取中文的拼音或转换中文替拼音
在MySQL中获取中文的拼音或转换中文为拼音 MySQL ------------------------------------- 分页:select * from xxx limit 0,10 ? ...
- python编写ATM类_Python中编写类的各种技巧和方法
有关 Python 内编写类的各种技巧和方法(构建和初始化.重载操作符.类描述.属性访问控制.自定义序列.反射机制.可调用对象.上下文管理.构建描述符对象.Pickling).你可以把它当作一个教程, ...
- python dataframe函数_python pandas中DataFrame类型数据操作函数的方法
这篇文章主要介绍了关于python pandas中DataFrame类型数据操作函数的方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 python数据分析工具pandas中Data ...
- java汉字转换拼音,获取汉字串拼音首字母
首先要下载 pinyin4j 的jar包 import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j ...
- python将object转换为float_DataFrame中的object转换成float的方法
DataFrame中的object转换成float的方法 数据类型转换: 今天遇到一个问题,就是DataFrame类型的数据里是str型的数字,想把数字转换为int 或float:百度没有发现好的,也 ...
最新文章
- Mac-使用文本编辑的html浏览器打开出现源代码问题
- 整理前端工作中的可复用代码(二):拓展spark-md5,支持计算网络文件md5
- 消息队列之ActiveMQ安装配置
- 标准模板库(STL)学习指南之set集合
- heic怎么查看,如何打开heic
- php mysql 云虚拟机_虚拟机+apache+php+mysql 环境安装配置
- 计算机技能大赛试题及答案,全国中职计算机技能大赛(园区网)试题及参考答案...
- UVA12633 Super Rooks on Chessboard
- Visual Studio 打开程序提示仅我的代码怎么办
- linux利用内存加快读盘速度,Linux性能优化从入门到实战:10 内存篇:如何利用Buffer和Cache优化程序的运行效率?...
- java运行python3_Python3:如何从python运行java类文件
- 把c的char数组转换为python image的代码
- 《MTP中高层实战管理专家周黎辉》
- keil中c语言定义数组,如题,KeilC51位变量能不能定义数组
- JavaScript 使用
- 泡泡堂、QQ堂游戏通信架构分析
- 免费视频直播、点播H5播放器SkeyeWebPlayer适配移动端
- Excel 2010光标移动到单元格边框时,不显示小十字(亲自实践)
- 2022爱分析・数据库厂商全景报告 | 爱分析报告
- Windows获取系统唯一标识UUID