Deutsch   English   Français   Italiano  
<v6ufmc$3mo35$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna <HenHanna@devnull.tb>
Newsgroups: comp.lang.python,comp.lang.lisp
Subject: Re: How do i get multiple Min() values?
Date: Sat, 13 Jul 2024 11:06:04 -0700
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <v6ufmc$3mo35$1@dont-email.me>
References: <v6qu7m$2vg8q$1@dont-email.me> <v6tthj$3jj0a$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 13 Jul 2024 20:06:05 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0b2917fef9857da2f467d2527da3b2d2";
	logging-data="3891301"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19gCcpvIBVIzd+1phClfVop2WhRqwxX2mg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:isFCfBGRcH8wIZ7CAwG/7uYH7NU=
In-Reply-To: <v6tthj$3jj0a$1@dont-email.me>
Content-Language: en-US
Bytes: 2290

On 7/13/2024 5:56 AM, B. Pym wrote:
> HenHanna wrote:
> 
>>
>> How do i get multiple Min() values?
>>
>>            e.g.      for   Y = (x-2)*(x-3)   for x in range(-10,10)
>>                                     the min Y is hit twice
>>
>>
>> print(  min( ((x-2)*(x-3),  (x, (x-2, x-3)))
>>                                             for x in range(-10,10) ) )
>>
>>
>>
>> is this easy in Scheme(Gauche) ?
> 
> Gauche Scheme
> 
> (use gauche.collection) ;; fold2
> 
> (define (min-by fn lst)
>    (if (null? lst)
>      (values '() #f)
>      (fold2
>        (lambda (x best worth)
>          (let ((score (fn x)))
>            (cond ((< score worth) (values (list x) score))
>                  ((= score worth) (values (cons x best) worth))
>                  (#t (values best worth)))))
>        (take lst 1) (fn (car lst))
>        (cdr lst))))
> 
> (min-by (lambda(x) (* (- x 2) (- x 3))) (lrange -10 11))
> 
>    ===>
> (3 2)
> 0
>   

Thank you...   i think Python and Scheme(Gauche) should give
me this by default:

a list(collection) of all the
                        ( key1  "data1"  ... etc )
                        ( key2  "data2"  ... etc ) ...

     for which the Min key value was seen.