Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
return first pinyin letter of chinese word
# 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
You can’t perform that action at this time.