Created
April 22, 2011 10:13
-
-
Save scturtle/936408 to your computer and use it in GitHub Desktop.
return first pinyin letter of chinese word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
a=[ i.decode('utf8').encode('gbk') for i in | |
['澳', '怖', '错', '堕', '贰', '咐', '过', | |
'祸', '祸', '骏', '阔', '络', '穆', '诺', | |
'沤', '瀑', '群', '弱', '所', '唾', | |
'唾', '唾', '误', '褕', '孕', '座',] ] | |
def firstpy(s,code='utf8'): | |
s=s.decode(code).encode('gbk') | |
i=0 | |
while i<26 and a[i]<s: | |
i+=1 | |
return '%c' % (97+i) | |
if __name__=='__main__': | |
s='判断字符串首字母' | |
for i in range(0,len(s),3): | |
print firstpy(s[i:i+3]), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment