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.