Skip to content

Instantly share code, notes, and snippets.

@mahmoudhossam
Created November 7, 2011 04:55
Show Gist options
  • Save mahmoudhossam/1344210 to your computer and use it in GitHub Desktop.
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.
"""
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