> On 29 Aug 2020, at 13:42, Filipp Bakanov <[email protected]> wrote: > > I'd like to propose adding argmax and argmin functions to the python list. > These functions return the index of a maximum / minimum element of the list. > Eg: > > a = [1, 4, 2, 3] > print(a.argmax()) # 1 > print(a.argmin()) # 0 > > It's a very popular request (based on stackoverflow > https://stackoverflow.com/questions/16945518/finding-the-index-of-the-value-which-is-the-min-or-max-in-python > > <https://stackoverflow.com/questions/16945518/finding-the-index-of-the-value-which-is-the-min-or-max-in-python> > ), and currently there is no elegant way to find it. > > What do you think?
Just do this: >>> a=[1,4,2,3] >>> min(a) 1 >>> a.index(min(a)) 0 >>> a.index(max(a)) 1 Barry > _______________________________________________ > Python-ideas mailing list -- [email protected] > To unsubscribe send an email to [email protected] > https://mail.python.org/mailman3/lists/python-ideas.python.org/ > Message archived at > https://mail.python.org/archives/list/[email protected]/message/NDEJQUABSNJSK76UDKHFTFW7YIFXJN5B/ > Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/[email protected]/message/M7JLKDB5RE3LPPDICYG7BPLOLA4STPHG/ Code of Conduct: http://python.org/psf/codeofconduct/
