Answer the question
In order to leave comments, you need to log in
How to sort the characters of a string in the order "AaBbCc..." in python?
How to sort the characters of a string in the order "AaBbCc..." in python (Each character only occurs once in the source string eg "baBcAC"?
Answer the question
In order to leave comments, you need to log in
Yes, do not care how many times it occurs:
order = {c: i for i, c in enumerate(
"AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz")}
s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit"
print(''.join(sorted(s, key=lambda c: order.get(c, 99))))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question