Sort a string in lexicographic order python

Do not use lambda functions when there’s builtin ones for the job. Also never use the cmp argument of sorted because it’s deprecated:

sorted(s, key=str.lower)

or

sorted(s, key=str.upper)

But that may not keep ‘A’ and ‘a’ in order, so:

sorted(sorted(s), key=str.upper)

that will and, by the nature of sorted the operation will be very fast for almost sorted lists (the second sorted).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)