Created
December 5, 2019 01:17
-
-
Save FerdinaKusumah/d6fffaf8efe868b56e214572edf51df6 to your computer and use it in GitHub Desktop.
Find Min Max Index In LIst
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 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