Created
November 13, 2011 22:39
-
-
Save samstewart/1362847 to your computer and use it in GitHub Desktop.
Find the index of a maximum or minimum element of a python list
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
#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)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Love functional programming!