Python's way to get a set of Chinese pinyin first letters

Source: Internet
Author: User
Tags ord

This article illustrates how Python obtains a set of Chinese pinyin initials. Share to everyone for your reference. The implementation methods are as follows:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 The 67 68 69 70 71 72 73 74 75 76 77 78 79 80 #!/usr/bin/env python #-*-coding:utf-8-*-def multi_get_letter (str_input): If Isin Stance (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:retu Rn_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 >=-20 319 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 >=-162 <= -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:re Turn ' y ' if ASC >= -11055 and ASC <= -10247:return ' z ' return ' def Main (str_input): a = Multi_get_letter (Str_inpu T) b = ' For i in a:b= b+i print b if __name__ = ' __main__ ': str_input=u ' Welcome to You ' main (str_input)

I hope this article will help you with your Python programming.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.