Unknown character order

I am sorting a large list of values ​​and I am using the sort.exe file (site here , zip file with sort.exe here) which is a UNIX port of 'sort' for Windows. However, I cannot figure out in what order it sorts it. So, I took a list of ASCII characters and ran the sort file to see how it was created. Does anyone know what character order this is, or more precisely, how can I implement it in Python?

Edit : chcp was originally 437 (US), I also tried with 65001 (Unicode), both gave me the same result.

╔═══════╦══════════╗
β•‘ ASCII β•‘ SORT.EXE β•‘
╠═══════╬══════════╣
β•‘ !     β•‘ '        β•‘
β•‘ "     β•‘ -        β•‘
β•‘ #     β•‘ !        β•‘
β•‘ $     β•‘ "        β•‘
β•‘ %     β•‘ #        β•‘
β•‘ &     β•‘ $        β•‘
β•‘ '     β•‘ %        β•‘
β•‘ (     β•‘ &        β•‘
β•‘ )     β•‘ (        β•‘
β•‘ *     β•‘ )        β•‘
β•‘ +     β•‘ *        β•‘
β•‘ ,     β•‘ ,        β•‘
β•‘ -     β•‘ .        β•‘
β•‘ .     β•‘ /        β•‘
β•‘ /     β•‘ :        β•‘
β•‘ 0     β•‘ ;        β•‘
β•‘ 1     β•‘ ?        β•‘
β•‘ 2     β•‘ @        β•‘
β•‘ 3     β•‘ [        β•‘
β•‘ 4     β•‘ \        β•‘
β•‘ 5     β•‘ ]        β•‘
β•‘ 6     β•‘ ^        β•‘
β•‘ 7     β•‘ _        β•‘
β•‘ 8     β•‘ `        β•‘
β•‘ 9     β•‘ {        β•‘
β•‘ :     β•‘ |        β•‘
β•‘ ;     β•‘ }        β•‘
β•‘ <     β•‘ ~        β•‘
β•‘ =     β•‘ +        β•‘
β•‘ >     β•‘ <        β•‘
β•‘ ?     β•‘ =        β•‘
β•‘ @     β•‘ >        β•‘
β•‘ A     β•‘ 0        β•‘
β•‘ B     β•‘ 1        β•‘
β•‘ C     β•‘ 2        β•‘
β•‘ D     β•‘ 3        β•‘
β•‘ E     β•‘ 4        β•‘
β•‘ F     β•‘ 5        β•‘
β•‘ G     β•‘ 6        β•‘
β•‘ H     β•‘ 7        β•‘
β•‘ I     β•‘ 8        β•‘
β•‘ J     β•‘ 9        β•‘
β•‘ K     β•‘ a        β•‘
β•‘ L     β•‘ A        β•‘
β•‘ 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        β•‘
β•‘ [     β•‘ i        β•‘
β•‘ \     β•‘ I        β•‘
β•‘ ]     β•‘ j        β•‘
β•‘ ^     β•‘ J        β•‘
β•‘ _     β•‘ k        β•‘
β•‘ `     β•‘ K        β•‘
β•‘ a     β•‘ l        β•‘
β•‘ b     β•‘ L        β•‘
β•‘ c     β•‘ m        β•‘
β•‘ d     β•‘ M        β•‘
β•‘ e     β•‘ n        β•‘
β•‘ f     β•‘ N        β•‘
β•‘ g     β•‘ o        β•‘
β•‘ h     β•‘ O        β•‘
β•‘ i     β•‘ 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        β•‘
β•šβ•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•

      

+3


source to share


1 answer


It is very similar to sort -df

( -d

for dictionary order, -f

for ignore case) on the GNU sort

I have. However, '

and -

are at the top. It looks like it might have been solved in the comments, but for future reference:

To sort the rows in the custom procedure in Python, one of the ways is to use maketrans()

, and translate()

your order key, for example:



ascii = '!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'
mapped = '\'-!"#$%&()*,./:;?@[\\]^_`{|}~+<=>0123456789aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'
trans = str.maketrans(mapped, ascii)
print("".join(sorted(ascii, key=lambda s: s.translate(trans)))) # prints mapped

      

+2


source







All Articles