Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Malcolm McLean Newsgroups: comp.lang.c Subject: Re: Baby X is bor nagain Date: Wed, 19 Jun 2024 10:25:08 +0100 Organization: A noiseless patient Spider Lines: 33 Message-ID: References: <20240613002933.000075c5@yahoo.com> <20240613174354.00005498@yahoo.com> <20240617002924.597@kylheku.com> <20240618115650.00006e3f@yahoo.com> <20240618184026.000046e1@yahoo.com> <877celzx14.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 19 Jun 2024 11:25:08 +0200 (CEST) Injection-Info: dont-email.me; posting-host="1546666429f4a47bce7f01cf2bfd5cd4"; logging-data="2001726"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RxjUiYbyL6/Y2EguTG32rDlja+WCOtK4=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:lRzdon+96HEyTxPNKl+IV6Y9Gj0= In-Reply-To: <877celzx14.fsf@nosuchdomain.example.com> Content-Language: en-GB Bytes: 3044 On 18/06/2024 23:49, Keith Thompson wrote: > Malcolm McLean 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. > > > https://docs.python.org/3/library/functions.html#sorted > https://docs.python.org/3/library/stdtypes.html#list.sort > > 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