unicode

Does Python 3 string ordering depend on locale?

纵饮孤独 提交于 2020-08-27 22:04:27
问题 Do Python's str.__lt__ or sorted order characters based on their unicode index or by some locale-dependent collation rules? 回答1: No, string ordering does not take locale into account. It is based entirely on the Unicode codepoint sort order. The locale module does provide you with a locale.strxform() function that can be used for locale-specific sorting: import locale sorted(list_of_strings, key=locale.strxfrm) This tool is quite limited; for any serious collation task you probably want to