Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Created December 5, 2019 01:17
Show Gist options
  • Save FerdinaKusumah/d6fffaf8efe868b56e214572edf51df6 to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/d6fffaf8efe868b56e214572edf51df6 to your computer and use it in GitHub Desktop.
Find Min Max Index In LIst
"""Find index min and max in list"""
a = [4, 3, 7, 2, 12]
def get_min(arr: list) -> int:
return min(range(len(arr)), key=arr.__getitem__)
def get_max(arr: list) -> int:
return max(range(len(arr)), key=arr.__getitem__)
min_index_value = get_min(a)
print("Min index value is {}".format(min_index_value))
# Min index value is 3
max_index_value = get_max(a)
print("Max index value is {}".format(max_index_value))
# Max index value is 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment