python汉字拼音查询_python获取一组汉字的拼音首字母
下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
#!/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[0]) * 256 + ord(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 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)
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。
python汉字拼音查询_python获取一组汉字的拼音首字母相关推荐
- python汉字拼音查询_python获取一组汉字拼音首字母的方法
本文实例讲述了python获取一组汉字拼音首字母的方法.分享给大家供大家参考.具体实现方法如下: #!/usr/bin/env python # -*- coding: utf-8 -*- def m ...
- python汉字转拼音首字母_python获取一组汉字拼音首字母的方法
作者:不吃皮蛋 字体: 类型:转载 这篇文章主要介绍了python获取一组汉字拼音首字母的方法,涉及Python针对汉字操作的相关技巧,需要的朋友可以参考下 本文实例讲述了python获取一组汉字拼音 ...
- python怎么识别拼音-python获取一组汉字拼音首字母的方法
本文实例讲述了python获取一组汉字拼音首字母的方法.分享给大家供大家参考.具体实现方法如下: #!/usr/bin/env python # -*- coding: utf-8 -*- def m ...
- python咋变汉语_python实现将汉字转换成汉语拼音的库
本文实例讲述了python实现将汉字转换成汉语拼音的库.分享给大家供大家参考.具体分析如下: 下面的这个python库可以很容易的将汉字转换成拼音,其中用到了一个word.data 的字典,可点击此处 ...
- 中文汉字转拼音——大写(默认),小写,首字母大写
...好吧先上效果图~ 主要代码: public class MainActivity extends Activity {private TextView tv_test;String str = ...
- python实现火车票查询_Python脚本实现12306火车票查询系统
最近我看到看到使用python实现火车票查询,我自己也实现了,感觉收获蛮多的,下面我就把每一步骤都详细给分享出来.(注意使用的是python3) 首先我将最终结果给展示出来: 在cmd命令行执行:py ...
- python数据库模糊查询_Python操作mongodb数据库进行模糊查询操作示例
本文实例讲述了Python操作mongodb数据库进行模糊查询操作.分享给大家供大家参考,具体如下: # -*- coding: utf-8 -*- import pymongo import re ...
- python提取矩阵元素_python获取array中指定元素的示例
python获取array中指定元素的示例 对于array,如2-D的array,如何取指定元素 设array为3*10的shape s = array([[ 0, 1, 2, 3, 4, 5, 6, ...
- mysql 拼音首字母_MySQL 获取某个字段的汉语拼音首字母 - 文章
在做一个商城的时候,需要用户能有切换城市的功能,城市列表按照汉语拼音首字母排序,城市的数据是从国家统计局扒下来的,只有城市的编码和城市的名称,通过下面的 MySQL 函数,获取某个汉语的首字母. CR ...
最新文章
- 基于脑电和特征加权阶段训练的驾驶员疲劳状态估计
- Sigmoid 函数(To be continued)
- XML Schema简介
- 文件查找-locate find 学习笔记
- oracle 加密怎么解密,oracle加密encrypt,解密decrypt,
- javamail腾讯企业邮箱发送邮件
- dj鲜生-31-用户中心-功能需求分析
- React的组件模式 1
- java项目命令编译,打包,运行
- java解析xml文件
- CSS3 Transform 变形
- 斯坦福大学的 CS231n课程
- 计算机一级office操作题题库百度云,不容错过!计算机等级考试题库之一级MS Office操作题与答案...
- MacOS下AndroidStudio无法启动
- 台式计算机怎么安装无线网卡,台式机用无线网卡,小编教你台式机怎么用无线网卡...
- 扒开系统调用的三层皮(上)
- HBase 记忆内容(简答题)
- codeforces1670F Jee, You See?(DP/位运算/前缀和/组合数)
- 苹果手机有4g信号但是微信未连接服务器,苹果5s有显示4g网络但无上微信 是不是那里设置了 今天才出现的...
- 数组排序(5) 快速排序之三指针分区法