I want to sort a string to a list in lexicographic order as
str='aAaBbcCdE'
to
['A','a','a','B','b','C','c','d','E']
but sorted() gives me this output:
['A','B','C','E','a','a','b','c','d']
How can I sort lexicographically?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do not use lambda functions when there’s builtin ones for the job. Also never use the
cmpargument of sorted because it’s deprecated:or
But that may not keep ‘A’ and ‘a’ in order, so:
that will and, by the nature of
sortedthe operation will be very fast for almost sorted lists (the secondsorted).