Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Created July 28, 2020 13:53
Show Gist options
  • Save FerdinaKusumah/f5ff17b1b2aa7d6241c9290e719761ee to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/f5ff17b1b2aa7d6241c9290e719761ee to your computer and use it in GitHub Desktop.
[Python] find min and max index
"""Find index min and max"""
num = [5, 8, 3, 4, 9, 2, 5, 10]
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__)
print(f'min index is {get_min(num)}')
# min index is 5
print(f'max index is {get_max(num)}')
# max index is 7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment