Python 3 字符串排序是否取决于语言环境?

Aiv*_*var 8 python unicode python-3.x

做Python的str.__lt__sorted顺序字符根据其Unicode索引或某些区域设置相关的排序规则?

Mar*_*ers 9

不,字符串排序不考虑语言环境。它完全基于 Unicode 代码点排序顺序。

locale模块确实为您提供了一个可用于特定于语言环境的排序的locale.strxform()函数

import locale

sorted(list_of_strings, key=locale.strxfrm)
Run Code Online (Sandbox Code Playgroud)

这个工具相当有限的; 对于任何严肃的整理任务,您可能想要使用PyICU 库

import PyICU

collator = PyICU.Collator.createInstance(PyICU.Locale(locale_spec))
sorted(list_of_strings, key=collator.getSortKey)
Run Code Online (Sandbox Code Playgroud)