Python: Common function encapsulation

Source: Internet
Author: User

defIs_chinese (UCHAR):"""determine if a Unicode is a Chinese character"""        ifUchar >= u'\u4e00'  andUchar<=u'\u9fa5':                returnTrueElse:                returnFalsedefIs_number (UCHAR):"""determine if a Unicode is a number"""        ifUchar >= u'\u0030'  andUchar<=u'\u0039':                returnTrueElse:                returnFalsedefIs_alphabet (UCHAR):"""determine if a Unicode is an English letter"""        if(Uchar >= U'\u0041'  andUchar<=u'\u005a')or(Uchar >= U'\u0061'  andUchar<=u'\u007a'):                returnTrueElse:                returnFalsedefIs_other (UCHAR):"""determine if non-Chinese, numeric, and English characters"""        if  not(Is_chinese (UCHAR)orIs_number (UCHAR)orIs_alphabet (Uchar)):returnTrueElse:                returnFalsedefb2q (UCHAR):"""half angle turn full angle"""Inside_code=Ord (Uchar)ifinside_code<0x0020orinside_code>0x7e:#returns the original character without a half-width character                returnUcharifINSIDE_CODE==0X0020:#The formula for the other full-width half-width except the space is: half-width = full-width -0xfee0inside_code=0x3000Else: Inside_code+=0xfee0returnUNICHR (Inside_code)defq2b (UCHAR):"""full angle turning half angle"""Inside_code=Ord (Uchar)ifinside_code==0x3000: Inside_code=0x0020Else: Inside_code-=0xfee0ifinside_code<0x0020orinside_code>0x7e:#not half-width character returns the original character after the turn is finished                returnUcharreturnUNICHR (Inside_code)defstringq2b (ustring):"""Turn the string full-width to half- width"""        return "". Join ([Q2B (Uchar) forUcharinchustring]) defUniform (ustring):"""format string, complete full-width turn half-width, uppercase to lowercase work"""        returnstringq2b (ustring). Lower ()defstring2list (ustring):"""separate the ustring according to Chinese, letters, numbers"""retlist=[] utmp=[]         forUcharinchustring:ifIs_other (UCHAR):ifLen (utmp) = =0:Continue                        Else: Retlist.append ("". Join (utmp)) utmp=[]                Else: Utmp.append (UCHAR)ifLen (utmp)! =0:retlist.append ("". Join (utmp))returnRetlist

Python: Common function encapsulation

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.