Sujet : Re: Baby X is bor nagain
De : malcolm.arthur.mclean (at) *nospam* gmail.com (Malcolm McLean)
Groupes : comp.lang.cDate : 19. Jun 2024, 10:25:08
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4u85k$1t2pu$2@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
User-Agent : Mozilla Thunderbird
On 18/06/2024 23:49, Keith Thompson wrote:
Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
[...]
And it didn't take long to get Python to sort the list alphabetically,
but there seemed no way in to the sort comparision function
itself. And I had to give up.
<OT>
https://docs.python.org/3/library/functions.html#sorted
https://docs.python.org/3/library/stdtypes.html#list.sort
</OT>
key specifies a function of one argument that is used to extract a comparison key from each element in iterable (for example, key=str.lower). The default value is None (compare the elements directly).
You see the problem. I can sort on any field. I can sort alphaetically upwards and downwards. But I don't want to do that. I want to use a non-alphabetical comaprison function on two fields, and I need to specify that myself, because it's impossible that it is available anywhere. And that is to sort alphalbetically, except where the strings match except for an emedded "_L_" or "_D_" where the string wth the embedded "L" shoud be treated as closer to A than the string with the emebdded "_D_".
And I'm sure there is some way to achiev e this. But in C, it s achieved simply by declaring that qsort takes a function pointer to user-supplied code.
-- Check out my hobby project.http://malcolmmclean.github.io/babyxrc