Skip to content

Instantly share code, notes, and snippets.

@scturtle
Created April 22, 2011 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scturtle/936408 to your computer and use it in GitHub Desktop.
Save scturtle/936408 to your computer and use it in GitHub Desktop.
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