Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Find the index of a maximum or minimum element of a python list
#Gets the index of maximum element in a list. If a conflict occurs, the index of the last largest is returned
def maxl(l): return l.index(reduce(lambda x,y: max(x,y), l))
#Gets the index of minimum element in a list. If a conflict occurs, the index of the last smallest is returned
def minl(l): return l.index(reduce(lambda x,y: min(x,y), l))
#same as above but without the reduce coolness
def maxl(l): return l.index(max(l))
def minl(l): return l.index(min(l))
@samstewart

This comment has been minimized.

Copy link
Owner Author

commented Nov 13, 2011

Love functional programming!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.