min, max with position

Dennis Lee Bieber wlfraed at ix.netcom.com
Sat Jun 4 14:56:24 EDT 2022


On Sat, 4 Jun 2022 13:36:26 -0500, "Michael F. Stemper"
<michael.stemper at gmail.com> 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 write...

>>> def whatAt(function, data):
... 	what = function(data)
... 	at = data.index(what)
... 	return (at, what)
... 
>>> l = [	1.618033,	3.1415923536,	2.718282	]
>>> whatAt(min, l)
(0, 1.618033)
>>> whatAt(max, l)
(1, 3.1415923536)
>>> 

(properly, I should either reverse the order of the return value, or change
the name to atWhat() )


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/


More information about the Python-list mailing list