python - Unknown character ordering -
i'm sorting large list of values, , i'm using sort.exe file (site here, zip file sort.exe here) port of unix 'sort' command windows. however, can't figure out order it's sorting in. so, took ascii characters list, , ran sort file on see order produced. does know character ordering is, or more how can implement in python?
edit: chcp 437 (usa), tried 65001 (unicode), both giving me same output.
╔═══════╦══════════╗ ║ ascii ║ sort.exe ║ ╠═══════╬══════════╣ ║ ! ║ ' ║ ║ " ║ - ║ ║ # ║ ! ║ ║ $ ║ " ║ ║ % ║ # ║ ║ & ║ $ ║ ║ ' ║ % ║ ║ ( ║ & ║ ║ ) ║ ( ║ ║ * ║ ) ║ ║ + ║ * ║ ║ , ║ , ║ ║ - ║ . ║ ║ . ║ / ║ ║ / ║ : ║ ║ 0 ║ ; ║ ║ 1 ║ ? ║ ║ 2 ║ @ ║ ║ 3 ║ [ ║ ║ 4 ║ \ ║ ║ 5 ║ ] ║ ║ 6 ║ ^ ║ ║ 7 ║ _ ║ ║ 8 ║ ` ║ ║ 9 ║ { ║ ║ : ║ | ║ ║ ; ║ } ║ ║ < ║ ~ ║ ║ = ║ + ║ ║ > ║ < ║ ║ ? ║ = ║ ║ @ ║ > ║ ║ ║ 0 ║ ║ b ║ 1 ║ ║ c ║ 2 ║ ║ d ║ 3 ║ ║ e ║ 4 ║ ║ f ║ 5 ║ ║ g ║ 6 ║ ║ h ║ 7 ║ ║ ║ 8 ║ ║ j ║ 9 ║ ║ k ║ ║ ║ l ║ ║ ║ m ║ b ║ ║ n ║ b ║ ║ o ║ c ║ ║ p ║ c ║ ║ q ║ d ║ ║ r ║ d ║ ║ s ║ e ║ ║ t ║ e ║ ║ u ║ f ║ ║ v ║ f ║ ║ w ║ g ║ ║ x ║ g ║ ║ y ║ h ║ ║ z ║ h ║ ║ [ ║ ║ ║ \ ║ ║ ║ ] ║ j ║ ║ ^ ║ j ║ ║ _ ║ k ║ ║ ` ║ k ║ ║ ║ l ║ ║ b ║ l ║ ║ c ║ m ║ ║ d ║ m ║ ║ e ║ n ║ ║ f ║ n ║ ║ g ║ o ║ ║ h ║ o ║ ║ ║ p ║ ║ j ║ p ║ ║ k ║ q ║ ║ l ║ q ║ ║ m ║ r ║ ║ n ║ r ║ ║ o ║ s ║ ║ p ║ s ║ ║ q ║ t ║ ║ r ║ t ║ ║ s ║ u ║ ║ t ║ u ║ ║ u ║ v ║ ║ v ║ v ║ ║ w ║ w ║ ║ x ║ w ║ ║ y ║ x ║ ║ z ║ x ║ ║ { ║ y ║ ║ | ║ y ║ ║ } ║ z ║ ║ ~ ║ z ║ ╚═══════╩══════════╝
it's similar sort -df
(-d
dictionary order, -f
ignore case) on gnu sort
have. however, '
, -
being @ top different. sounds may have been solved in comments, future reference:
to sort strings in custom order in python, 1 way use maketrans()
, translate()
in sort key, so:
ascii = '!"#$%&\'()*+,-./0123456789:;<=>?@abcdefghijklmnopqrstuvwxyz[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~' mapped = '\'-!"#$%&()*,./:;?@[\\]^_`{|}~+<=>0123456789aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz' trans = str.maketrans(mapped, ascii) print("".join(sorted(ascii, key=lambda s: s.translate(trans)))) # prints mapped
Comments
Post a Comment