Re: min, max with position

2022-06-05 Thread Michael F. Stemper
On 04/06/2022 14.08, Stefan Ram wrote: "Michael F. Stemper" writes: Are there similar functions that return not only the minimum or maximum value, but also its position? The maximum value does not need to have a unique position. Which is something that I'll just have to live with,

Re: min, max with position

2022-06-05 Thread Antoon Pardon
Op 5/06/2022 om 01:52 schreef Greg Ewing: On 5/06/22 10:07 am, dn wrote: On 05/06/2022 09.50, Chris Angelico wrote: min(enumerate(l), key=lambda x: x[1]) (0, 1.618033) But, but, but which of the above characters is an 'el' and which a 'one'??? (please have pity on us old f...s and the

Re: min, max with position

2022-06-04 Thread Dan Stromberg
On Sat, Jun 4, 2022 at 9:07 PM Greg Ewing wrote: > On 5/06/22 10:07 am, dn wrote: > > On 05/06/2022 09.50, Chris Angelico wrote: > > min(enumerate(l), key=lambda x: x[1]) > >> (0, 1.618033) > > > > But, but, but which of the above characters is an 'el' and which a > 'one'??? > > (please have

Re: min, max with position

2022-06-04 Thread Greg Ewing
On 5/06/22 10:07 am, dn wrote: On 05/06/2022 09.50, Chris Angelico wrote: min(enumerate(l), key=lambda x: x[1]) (0, 1.618033) But, but, but which of the above characters is an 'el' and which a 'one'??? (please have pity on us old f...s and the visually-challenged!) ell = l one = 1

Re: min, max with position

2022-06-04 Thread Chris Angelico
On Sun, 5 Jun 2022 at 08:09, dn wrote: > > On 05/06/2022 09.50, Chris Angelico wrote: > > No, but it shouldn't be too hard to make it if you want it. The > > obvious option of calling max/min on the enumerated list won't work on > > its own, since the index comes before the value, but with a key

Re: min, max with position

2022-06-04 Thread dn
On 05/06/2022 09.50, Chris Angelico wrote: > No, but it shouldn't be too hard to make it if you want it. The > obvious option of calling max/min on the enumerated list won't work on > its own, since the index comes before the value, but with a key > function it would work fine: >

Re: min, max with position

2022-06-04 Thread Chris Angelico
On Sun, 5 Jun 2022 at 08:00, dn wrote: > > On 05/06/2022 06.56, Dennis Lee Bieber wrote: > > On Sat, 4 Jun 2022 13:36:26 -0500, "Michael F. Stemper" > > declaimed the following: > > > >> > >> Are there similar functions that return not only the minimum > >> or maximum value, but also its

Re: min, max with position

2022-06-04 Thread dn
On 05/06/2022 06.56, Dennis Lee Bieber wrote: > On Sat, 4 Jun 2022 13:36:26 -0500, "Michael F. Stemper" > declaimed the following: > >> >> Are there similar functions that return not only the minimum >> or maximum value, but also its position? >> > If it isn't in the library reference

Re: min, max with position

2022-06-04 Thread Chris Angelico
On Sun, 5 Jun 2022 at 07:46, Michael F. Stemper wrote: > > Python contains built-in functions that return the minimum or > maximum items in a list. > > >>> l = [1.618033,3.141593,2.718282] > >>> min(l) > 1.618033 > >>> max(l) > 3.141593 > >>> > > Are there similar functions that

Re: min, max with position

2022-06-04 Thread Michael F. Stemper
On 04/06/2022 13.56, Dennis Lee Bieber wrote: On Sat, 4 Jun 2022 13:36:26 -0500, "Michael F. Stemper" declaimed the following: Are there similar functions that return not only the minimum or maximum value, but also its position? If it isn't in the library reference manual, NO...

Re: min, max with position

2022-06-04 Thread Alan Bawden
"Michael F. Stemper" writes: Are there similar functions that return not only the minimum or maximum value, but also its position? >>> specialmin(l) (0,1.618033) >>> specialmax(l) 3.141593 >>> I believe that what you are looking for is usually called "argmax" and

Re: min, max with position

2022-06-04 Thread Dennis Lee Bieber
On Sat, 4 Jun 2022 13:36:26 -0500, "Michael F. Stemper" declaimed the following: > >Are there similar functions that return not only the minimum >or maximum value, but also its position? > If it isn't in the library reference manual, NO... But it also isn't that difficult to

min, max with position

2022-06-04 Thread Michael F. Stemper
Python contains built-in functions that return the minimum or maximum items in a list. >>> l = [1.618033,3.141593,2.718282] >>> min(l) 1.618033 >>> max(l) 3.141593 >>> Are there similar functions that return not only the minimum or maximum value, but also its position? >>> specialmin(l)