Get the App
SLTechnology News&Howtos  ›  Development  › 

How to return the minimum index in Python

Shulou Source: shulou.com Published: 2022-06-01 22:41:24 10月19日 Update

Today, I would like to share with you the relevant knowledge points about how to return the minimum index in Python. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

Returns the index of the smallest item in the list

Def indexofMin (arr): minindex = 0 currentindex = 1 while currentindex < len (arr): if arr [currentindex] < arr [minindex]: minindex = currentindex currentindex + = 1 return minindexarr = [3, 5, 2, 1] print (indexofMin (arr))

Add: python returns the maximum (minimum) value in the list and its index

1. Returns the maximum of the list

Usage: max ()

Its syntax: this function returns the maximum value of a given parameter, which can be a sequence.

N = max (list) # list represents the list of maximum values to be returned.

Result: returns the maximum value in the list element

List1 = [123,456,789] list2 = ['123,' 456, '789'] list3 = ['abc',' abb', 'acb'] print (max (list1)) # 789print (max (list2)) # 789print (max (list3)) # acb2. Returns the index of the maximum value of the list

Usage: use max to find the maximum value in the list

Use index () to find the index with the maximum value

This function returns the index of the given parameter, which is an element in the sequence.

List1.index (max (list1))

The result returns the index of the parameter in the list

List1 = [123,456,789] print (list1.index (456)) # 1print (list1.index (max (list1) # 2

The minimum value only needs to be changed from max to min.

These are all the contents of the article "how to return the minimum Index in Python". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Tags: Index maximum maximum minimum parameter knowledge article usage element content function sequence method result different big most that is more knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB macOS Xiaomi Linux