新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
python如何實現(xiàn)按中文拼音對字符串排序
python如何實現(xiàn)按中文拼音對字符串排序?這個問題可能是我們?nèi)粘W習或工作經(jīng)常見到的。希望通過這個問題能讓你收獲頗深。下面是小編給大家?guī)淼膮⒖純?nèi)容,讓我們一起來看看吧!
芒市網(wǎng)站建設公司成都創(chuàng)新互聯(lián),芒市網(wǎng)站設計制作,有大型網(wǎng)站制作公司豐富經(jīng)驗。已為芒市超過千家提供企業(yè)網(wǎng)站建設服務。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站建設要多少錢,請找那個售后服務好的芒市做網(wǎng)站的公司定做!
安裝中文庫
sudo apt-get update sudo apt-get install language-pack-zh-hans-base sudo dpkg-reconfigure locales
使用
import locale locale.setlocale(locale.LC_COLLATE, 'zh_CN.UTF8') cmp = locale.strcoll courses.sort(lambda x, y: cmp(x.course_name, y.course_name))
測試用例
輸入
# -*- coding: utf-8 -*- import locale locale.setlocale(locale.LC_COLLATE, 'zh_CN.UTF8') cmp = locale.strcoll items = list('自掛東南枝'.decode('utf-8')) print 'before'.center(10, '=') print ''.join(items) items.sort(lambda x, y: cmp(x, y)) print 'after'.center(10, '=') print ''.join(items)
輸出
==before== 自掛東南枝 ==after=== 東掛南枝自
感謝各位的閱讀!看完上述內(nèi)容,你們對python如何實現(xiàn)按中文拼音對字符串排序大概了解了嗎?希望文章內(nèi)容對大家有所幫助。如果想了解更多相關文章內(nèi)容,歡迎關注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
網(wǎng)頁名稱:python如何實現(xiàn)按中文拼音對字符串排序
鏈接分享:http://www.dlmjj.cn/article/pddghg.html