# -*- coding: utf-8 -*-
#pip install pypinyin
# @Function: 中文排序
from itertools import chain
from pypinyin import pinyin, Style
def to_pinyin(s):
'''转拼音
'ni3hao3ma'
'''
return ''.join(chain.from_iterable(pinyin(s, style=Style.TONE3)))
print(sorted(['美国', '中国', '日本'])) # 美m 中z 日r abcdefghijkl[m]nopq[r]stuvwsy[z]
# ['中国', '日本', '美国']
print(sorted(['美国', '中国', '日本'], key=to_pinyin)) # 美m 中z 日r abcdefghijkl[m]nopq[r]stuvwsy[z]
# ['美国', '日本', '中国']