Python not sorting unicode properly. Strcoll doesn't help

后端 未结 6 1025
执笔经年
执笔经年 2020-11-30 04:05

I\'ve got a problem with sorting lists using unicode collation in Python 2.5.1 and 2.6.5 on OSX, as well as on Linux.

import locale   
locale.setlocale(loca         


        
6条回答
  •  鱼传尺愫
    2020-11-30 04:43

    import locale
    from functools import cmp_to_key
    iterable = [u'a', u'z', u'ą']
    sorted(iterable, key=cmp_to_key(locale.strcoll))  # locale-aware sort order
    

    (Ref.: http://docs.python.org/3.3/library/functools.html)

提交回复
热议问题