汉字首字母拼音排序-Python

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/baishengxu/article/details/83959179
  1. 安装pypinyin,目的是将中文转换成拼音
 pip install pypinyin
  1. 利用sort()函数进行排序
from pypinyin import lazy_pinyin
chinese_list=[u'中国人', u'啊', u'你好', u'台湾人'] #只支持unicode string
chinese_list= sorted(chinese_list, key=lambda x: lazy_pinyin(x.lower())[0][0])
print(chinese_list)

猜你喜欢

转载自blog.csdn.net/baishengxu/article/details/83959179
今日推荐