Re: Request for argmax(list) and argmin(list)

2021-09-02 Thread Dan Stromberg
How about this?:

python3 -c 'list_ = [1, 3, 5, 4, 2]; am = max((value, index) for index,
value in enumerate(list_)); print(am)'


On Wed, Sep 1, 2021 at 6:51 AM ABCCDE921 
wrote:

> Because that does 2 passes over the entire array when you only need one
> and there is no option to specify if you want the leftmost or rightmost
> element
>
>
> On Wednesday, September 1, 2021 at 12:02:29 PM UTC+5:30, Paul Bryan wrote:
> > Why not:
> >
> > >>> l = [1, 3, 5, 9, 2, 7]
> > >>> l.index(max(l))
> > 3
> > >>> l.index(min(l))
> > 0
> > On Tue, 2021-08-31 at 21:25 -0700, ABCCDE921 wrote:
> > > I dont want to import numpy
> > >
> > > argmax(list)
> > > returns index of (left most) max element
> > >
> > > argmin(list)
> > > returns index of (left most) min element
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request for argmax(list) and argmin(list)

2021-09-01 Thread Calvin Spealman
If only there were a library that already provides exactly the functions
you're asking for... 🤔

On Wed, Sep 1, 2021 at 9:54 AM ABCCDE921 
wrote:

> Because that does 2 passes over the entire array when you only need one
> and there is no option to specify if you want the leftmost or rightmost
> element
>
>
> On Wednesday, September 1, 2021 at 12:02:29 PM UTC+5:30, Paul Bryan wrote:
> > Why not:
> >
> > >>> l = [1, 3, 5, 9, 2, 7]
> > >>> l.index(max(l))
> > 3
> > >>> l.index(min(l))
> > 0
> > On Tue, 2021-08-31 at 21:25 -0700, ABCCDE921 wrote:
> > > I dont want to import numpy
> > >
> > > argmax(list)
> > > returns index of (left most) max element
> > >
> > > argmin(list)
> > > returns index of (left most) min element
> --
> https://mail.python.org/mailman/listinfo/python-list
>
>

-- 

CALVIN SPEALMAN

SENIOR QUALITY ENGINEER

calvin.speal...@redhat.com  M: +1.336.210.5107
[image: https://red.ht/sig] 
TRIED. TESTED. TRUSTED. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request for argmax(list) and argmin(list)

2021-09-01 Thread ABCCDE921
Because that does 2 passes over the entire array when you only need one and 
there is no option to specify if you want the leftmost or rightmost element 


On Wednesday, September 1, 2021 at 12:02:29 PM UTC+5:30, Paul Bryan wrote:
> Why not: 
> 
> >>> l = [1, 3, 5, 9, 2, 7] 
> >>> l.index(max(l)) 
> 3 
> >>> l.index(min(l)) 
> 0
> On Tue, 2021-08-31 at 21:25 -0700, ABCCDE921 wrote: 
> > I dont want to import numpy 
> > 
> > argmax(list) 
> > returns index of (left most) max element 
> > 
> > argmin(list) 
> > returns index of (left most) min element
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Request for argmax(list) and argmin(list)

2021-09-01 Thread Peter Otten

On 01/09/2021 06:25, ABCCDE921 wrote:

I dont want to import numpy

argmax(list)
returns index of (left most) max element



>>> import operator
>>> second = operator.itemgetter(1)
>>> def argmax(values):
return max(enumerate(values), key=second)[0]

>>> argmax([1, 2, 3, 0])
2


  argmin(list)
returns index of (left most) min element


This is left as an exercise;)



--
https://mail.python.org/mailman/listinfo/python-list


Re: Request for argmax(list) and argmin(list)

2021-08-31 Thread Paul Bryan
Why not:

>>> l = [1, 3, 5, 9, 2, 7]
>>> l.index(max(l))
3
>>> l.index(min(l))
0

On Tue, 2021-08-31 at 21:25 -0700, ABCCDE921 wrote:
> I dont want to import numpy
> 
> argmax(list) 
>    returns index of (left most) max element
> 
>  argmin(list)
>    returns index of (left most) min element

-- 
https://mail.python.org/mailman/listinfo/python-list


Request for argmax(list) and argmin(list)

2021-08-31 Thread ABCCDE921
I dont want to import numpy

argmax(list) 
   returns index of (left most) max element

 argmin(list)
   returns index of (left most) min element
-- 
https://mail.python.org/mailman/listinfo/python-list