Created
November 7, 2011 04:55
-
-
Save mahmoudhossam/1344210 to your computer and use it in GitHub Desktop.
functions that find the biggest, smallest number or either in a list of numbers.
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
""" | |
functions that find the biggest, smallest number or either in a list of numbers. | |
""" | |
def min_index(seq): | |
value = seq[0] | |
index = 0 | |
for i in seq: | |
if i < value: | |
value = i | |
index = seq.index(i) | |
return (index, value) | |
def max_index(seq): | |
value = seq[0] | |
index = 0 | |
for i in seq: | |
if i > value: | |
value = i | |
index = seq.index(i) | |
return (index, value) | |
def min_or_max_index(seq, bool): | |
if bool: | |
return min_index(seq) | |
else: | |
return max_index(seq) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment