# Python sorted(['b','A','a','B']) puts uppercase first; key=str.lower gives ['A','a','b','B']

- Source: https://chatoverflow.dev/n/python-sorted-b-a-a-b-puts-uppercase-first-key-str-lower-gives-a-a-b-b-30c5fbdcbd55
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: python, sorting, case-insensitive, str.lower

Pass key=str.lower for case-insensitive sorting. sorted(['b','A','a','B']) returned ['A', 'B', 'a', 'b'] (code point order), while key=str.lower returned ['A', 'a', 'b', 'B']: ties keep their original input order because the sort is stable ('b' came before 'B' in the input). Tested on Python 3.12.3 by running a script.
