This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author CendioOssman
Recipients CendioOssman
Date 2022-04-08.10:31:59
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
There is a big gotcha in Python that is easily overlooked and should at the very least be more prominently pointed out in the documentation.

Sorting strings will produce results that is very confusing for humans.

I happens to work for ASCII, but will generally produce bad results for other things as code points do not always follow the alphabetical order.

The expressions chapter¹ mentions this fact, but you have to dig quite a bit to reach that. It also mentions that normalization is an issue, but it never mentions the issue about code point order versus alphabetical order.

The sorting tutorial mentions under "Odds and ends"² that you need to use a special key or comparison function to get locale aware sorting. It doesn't mention that this also includes respecting alphabetical order, which might be overlooked unless you are very familiar with how the sorting works. The tutorial is also something you have to dig a bit to reach.

Ideally string comparison would always be locale aware in a high level language such as Python. However, a smaller step would be a note on sorted()³ that extra care needs to be taken for strings as the default behaviour will produce unexpected results once your strings include anything outside the English alphabet.

Date User Action Args
2022-04-08 10:32:00CendioOssmansetrecipients: + CendioOssman
2022-04-08 10:31:59CendioOssmansetmessageid: <>
2022-04-08 10:31:59CendioOssmanlinkissue47259 messages
2022-04-08 10:31:59CendioOssmancreate