When sorting the Python list, English comes first, but is there a way to make Hangul come first?
names = ["C", "AB", "N", "L", "DA", "AA", "D"]
sorted(names)
# # Output
["AA", "AB", "C", "DA", "A", "N", "D"]
# # Desired Output
["a", "n", "d", "AA", "AB", "C", "DA"]
Thank you.
sorting python list korean unicode
There must be a better way.;Write only in the way that came to mind right away.
;;In [1]: names
Out [1]: ["C", "AB", "ㄴ", "L", "DA", "AA", "D"]
In [2]: sorted(names)
Out [2]: ["AA", "AB", "C", "DA", "L", "N", "D"]
In [3]: sorted(sorted(names), key=lambdac:0 if re.search('[--heet]', c) else 1)
Out [3]: ["a", "n", "d", "AA", "AB", "C", "DA"]
© 2024 OneMinuteCode. All rights reserved.