Created
July 28, 2020 13:53
-
-
Save FerdinaKusumah/f5ff17b1b2aa7d6241c9290e719761ee to your computer and use it in GitHub Desktop.
[Python] find min and max index
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
"""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