diff --git a/README.md b/README.md index 3007c4a63..94d446585 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ * [`intersection_by`](#intersection_by) * [`last`](#last) * [`longest_item`](#longest_item) +* [`max_element_index`](#max_element_index) * [`max_n`](#max_n) * [`min_n`](#min_n) * [`most_frequent`](#most_frequent) @@ -774,6 +775,28 @@ longest_item([1, 2, 3], 'foobar') # 'foobar'
[⬆ Back to top](#contents) +### max_element_index + +Returns the pindex of the element with the maximum value in a list. + +Use `max()` and `list.index()` to get the maximum value in the list and return its index. + +```py +def max_element_index(arr): + return arr.index(max(arr)) +``` + +
+Examples + +```py +thon +max_element_index([5, 8, 9, 7, 10, 3, 0]) # 4 +``` +
+ +
[⬆ Back to top](#contents) + ### max_n Returns the `n` maximum elements from the provided list. diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json index 8de1a215f..2b3002102 100644 --- a/snippet_data/snippetList.json +++ b/snippet_data/snippetList.json @@ -788,6 +788,21 @@ "hash": "aca578491d9c055c793cf782db88f7e0c1de093c3e9ad09a72a59e75055b7581" } }, + { + "id": "max_element_index", + "type": "snippetListing", + "title": "max_element_index", + "attributes": { + "text": "Returns the pindex of the element with the maximum value in a list.\n\nUse `max()` and `list.index()` to get the maximum value in the list and return its index.\n\n", + "tags": [ + "list", + "beginner" + ] + }, + "meta": { + "hash": "b482aa65907f5e1516d22e1e1ba88a87234a83e8db220a11e9ea4687cee6376c" + } + }, { "id": "max_n", "type": "snippetListing", diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json index 0a1ddebfe..68089ae86 100644 --- a/snippet_data/snippets.json +++ b/snippet_data/snippets.json @@ -1043,6 +1043,26 @@ "hash": "aca578491d9c055c793cf782db88f7e0c1de093c3e9ad09a72a59e75055b7581" } }, + { + "id": "max_element_index", + "title": "max_element_index", + "type": "snippet", + "attributes": { + "fileName": "max_element_index.md", + "text": "Returns the pindex of the element with the maximum value in a list.\n\nUse `max()` and `list.index()` to get the maximum value in the list and return its index.\n\n", + "codeBlocks": { + "code": "def max_element_index(arr):\r\n return arr.index(max(arr))", + "example": "thon\r\nmax_element_index([5, 8, 9, 7, 10, 3, 0]) # 4" + }, + "tags": [ + "list", + "beginner" + ] + }, + "meta": { + "hash": "b482aa65907f5e1516d22e1e1ba88a87234a83e8db220a11e9ea4687cee6376c" + } + }, { "id": "max_n", "title": "max_n",