Created
July 9, 2026 12:54
-
-
Save bryan-lunt/364dd67d6ed2ce64c566fbbc7ec06bdc to your computer and use it in GitHub Desktop.
Python argmax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def argmax(a_list,key=lambda x:x): | |
| index = 0 | |
| maxval = key(a_list[0]) | |
| for i,e in enumerate(a_list[1:],1): | |
| v = key(e) | |
| if v > maxval: | |
| index = i | |
| maxval = v | |
| return index | |
| def argmax2(a_list,key=lambda x:x): | |
| index, value = max(enumerate(a_list), key=lambda y:key(y[1])) | |
| return index |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It needs to be benchmarked.