Nov-03-2025, 03:36 AM
there are different ways to do sorting in Python. but which way is correct? i have experienced order errors in the past but did not have time to explore why.
i will be sorting file paths where i do expect the '/' that delimits directory names plus a few control characters but specifically NOT the 4 characters with ASCII codes, in decimal, 28 to 31 inclusive. so what i do is translate '/' (decimal code 47) to decimal code 31 (octal 037, hexadecimal 1f) before sorting (using the "sort" command) and translating back afterwards. this should be straight forward in Python.
the above method through the sort command in Linux does work and gets the correct order. i would like to find a command/script in Python that carries out sorting and achieves the same order. if it does not have the translations for '/', then i can add that easy enough. i will look and see what method it used and applied that to my future code.
i will be sorting file paths where i do expect the '/' that delimits directory names plus a few control characters but specifically NOT the 4 characters with ASCII codes, in decimal, 28 to 31 inclusive. so what i do is translate '/' (decimal code 47) to decimal code 31 (octal 037, hexadecimal 1f) before sorting (using the "sort" command) and translating back afterwards. this should be straight forward in Python.
the above method through the sort command in Linux does work and gets the correct order. i would like to find a command/script in Python that carries out sorting and achieves the same order. if it does not have the translations for '/', then i can add that easy enough. i will look and see what method it used and applied that to my future code.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
