1.安装第三方模块
pip install xpinyin2.实现代码如下:
1 from xpinyin import Pinyin
2
3 def my_sort(wordlist): # 指定要排序的列表
4 pin = Pinyin() # 创建汉字转拼音的对象
5 temp = [] # 保存转换结果的空列表
6 for item in wordlist:
7 temp.append((pin.get_pinyin(item), item)) # 将汉字的拼音和汉字放到一个元组中,再添加到列表中
8 temp.sort() # 对列表进行排序
9 result = [] # 保存排序后的列表
10 for i in range(len(temp)): # 遍历排序后的列表
11 result.append(temp[i][1]) # 取出汉字保存到新列表中
12 return result # 返回排序后的列表3.调用函数即可
















