Skip to content

Instantly share code, notes, and snippets.

@bryan-lunt
Created July 9, 2026 12:54
Show Gist options
  • Select an option

  • Save bryan-lunt/364dd67d6ed2ce64c566fbbc7ec06bdc to your computer and use it in GitHub Desktop.

Select an option

Save bryan-lunt/364dd67d6ed2ce64c566fbbc7ec06bdc to your computer and use it in GitHub Desktop.
Python argmax
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
@bryan-lunt

Copy link
Copy Markdown
Author

It needs to be benchmarked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment